我想在我的数据集上使用elasticsearch执行地理位置查询,如下所示:
{"index": {"_index": "city","_type":"city_info", "_id":0} }
{"fields": { "city" : "AGAWAM",
"loc" : [ -72.622739, 42.070206 ],
"pop" : 15338, "state" : "MA"},
"id" : "01001" ,
"type" : "add"}
...
我可以执行许多查询或聚合,没有任何问题,但当涉及到使用地理距离过滤器或任何在地理坐标上工作的查询时,它不起作用。下面是我的映射测试:
PUT /city/_mappings
{
"properties": {
"fields.loc": {
"type": "geo_point"
}
}
}
我得到了这个错误。
{
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "mapper [fields.loc] of different type, current_type [float], merged_type [geo_point]"
}
],
"type" : "illegal_argument_exception",
"reason" : "mapper [fields.loc] of different type, current_type [float], merged_type [geo_point]"
},
"status" : 400
}
所以看起来我的"fields.loc“是一个浮点数,而在JSON中它是一个带有浮点值的数组。我试着看看"loc“的实际类型是什么,它确实是一个浮动,我不明白为什么:
GET /city/_mapping
{
"city" : {
"mappings" : {
"properties" : {
"fields" : {
"properties" : {
"city" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"loc" : {
"type" : "float"
...
所以我不理解,或者更确切地说,我不知道如何将"loc“从一个浮点型修改为一个geo_point。由于我是elasticsearch的初学者,我只在cURL中使用了elasticsearch和kibana。
发布于 2020-03-16 14:55:29
一旦您隐式地将数据类型设置为float (通过批量同步,您可能已经这样做了),就很难将float转换为geo_points。我建议删除索引,使用geo_point
数据类型设置正确的映射,然后重新同步所有内容。
如果您想深入了解,请看一下_reindex
应用编程接口。这是一个quick tut。当您的系统在生产环境中运行时,您可能会遇到这种情况,在生产环境中,现在可以选择删除。
仅供参考,不推荐使用custom _doc类型。
https://stackoverflow.com/questions/60707709
复制