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