Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 仅索引映射中存在的字段-ElasticSearch v5.2.2_Javascript_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Javascript,elasticsearch" /> elasticsearch,Javascript,elasticsearch" />

Javascript 仅索引映射中存在的字段-ElasticSearch v5.2.2

Javascript 仅索引映射中存在的字段-ElasticSearch v5.2.2,javascript,elasticsearch,Javascript,elasticsearch,在为mine typetype1创建映射时,我声明了3个字段 但是在索引数据时,主体也可以有许多其他字段,这些字段在我的映射中不存在 esClient.indices.putMapping({ index: 'index1', type: 'type1', body: { properties: { Name: { type: 'string', },

在为mine type
type1
创建映射时,我声明了3个字段

但是在索引数据时,
主体
也可以有许多其他字段,这些字段在我的
映射中不存在

esClient.indices.putMapping({
    index: 'index1',
    type: 'type1',
    body: {
        properties: {
            Name: {
                type: 'string',
            },
            Description: {
                type: 'string',
            },
            Address: {
                type: 'string',
            },
        }
    }
})
在这里,
数据
对象还有两个字段
组织
,默认情况下,ElasticSearch将为矿山映射中未提及的额外字段创建类型

const data = {
    Name: 'pauline',
    Description: 'he\'s pauline from academy',
    Address: 'avenue street',
    class: 'Standard form 1', // ignore this while indexing
    organization: 'Escalar Communications' // ignore this while indexing
}
那么,是否有一种方法可以只索引
\u映射中存在的字段数据
,并排除其他字段数据,我指的是一些要设置的选项

否则我得自己做

esClient.index({
    index: 'index1',
    type: 'type1',
    body: data,
}, (error, response) => {
    console.log(error, response);
});

是的,您可以通过在映射中添加
“dynamic”:false来忽略不在映射中的字段。默认情况下,这是真的

esClient.indices.putMapping({
    index: 'index1',
    type: 'type1',
    body: {
        dynamic: false,               <--- add this
        properties: {
            Name: {
                type: 'string',
            },
            Description: {
                type: 'string',
            },
            Address: {
                type: 'string',
            },
        }
    }
})
esClient.index.putMapping({
索引:“index1”,
类型:“类型1”,
正文:{

dynamic:false,你需要删除索引并重新创建它是的,我也这样做了,删除了索引,创建了它,用
dyanmic:false
对body object set进行了映射,并用额外字段索引了数据,这些额外字段被索引了。你能用从
curl-XGET localhost:9中得到的结果更新你的问题吗200/index1/_-mapping/type1
?您运行的是哪个版本的ES?应该没有任何区别