在mt node app中,我使用Elastic-search作为后端。因为我使用以下查询创建了一个“模板”。
{
"template" : "*",
"settings" : {
"index.number_of_shards" : 3,
"index.number_of_replicas" : 1
},
"mappings" : {
"_default_" : {
"_source" : { "enabled" : true,
"compress" : true },
"_all" : { "enabled" : false },
"properties" : {
"xx": { "type": "string", "index": "not_analyzed" },
"yy": { "type": "integer", "index": "not_analyzed" },
"zz": { "type": "integer", "index": "not_analyzed" },
"aa": { "type": "integer", "index": "not_analyzed" },
"locaiton": { "type": "geo_point", "index": "not_analyzed" }
}
}
}
}
我创建了一个索引名称“Temp
”,因此上面的模板将适用于此。它的工作正常。但我希望字段名称与映射完全相同:
考虑我的数据如下:
curl -XPOST "192.168.1.107:9200/temp/place" -d'{ "xx" : "asdfg",
"yy":34,
"zz":67,
"aa":78,
"locaiton":'78.80, 10.89' }'
工作:
但请考虑一下:
curl -XPOST "192.168.1.107:9200/temp/place" -d'{ "xx" : "asdfg",
"yyyyyyyyyy":34,------------------------> changing the field name is also accepting.
"zz":67,
"aa":78,
"locaiton":'78.80, 10.89' }'
我想在这里收到错误消息。是否有可能在Elasticsearch中。请分享您的想法。提前谢谢。
答案 0 :(得分:0)
是的可能,我找到了解决方案:
创建index-template时将动态属性设置为strict:
{
"template" : "*",
"settings" : {
"index.number_of_shards" : 3,
"index.number_of_replicas" : 1
},
"mappings" : {
"_default_" : {
"_source" : { "enabled" : true,
"compress" : true },
"_all" : { "enabled" : false },
"dynamic":"strict",
"properties" : {
"xx": { "type": "string", "index": "not_analyzed" },
"yy": { "type": "integer", "index": "not_analyzed" },
"zz": { "type": "integer", "index": "not_analyzed" },
"aa": { "type": "integer", "index": "not_analyzed" },
"locaiton": { "type": "geo_point", "index": "not_analyzed" }
}
}
}
}