rest - Elasticsearch:地理位置距离查询错误

标签 rest elasticsearch location

这是我的映射:

$ curl -XGET http://localhost:9200/test-index/dev/_mapping?pretty
{
  "test-index" : {
    "mappings" : {
      "dev" : {
        "properties" : {
          "Coordinates" : {
            "type" : "double"
          },
          "DisplayName" : {
            "type" : "string"
          },
          "Location" : {
            "type" : "string"
          },
          "RawLocation" : {
            "type" : "string"
          },
          "Reputation" : {
            "type" : "string"
          }
        }
      }
    }
  }
}

我的目标是在“坐标”上运行地理距离查询。

我使用以下坐标格式:
"location": [ -73.983, 40.719 ]

以下是一些结果:
$ curl -XGET http://localhost:9200/test-index/dev/_search?pretty
...
{
      "_index" : "test-index",
      "_type" : "dev",
      "_id" : "Arindam Nayak",
      "_score" : 1.0,
      "_source":{"RawLocation": "Pune, India", "Reputation": "101", "DisplayName": "Arindam Nayak", "Location": "Pune, Maharashtra 411001, India", "Coordinates": [73.8567437, 18.5204303]}
 }, 
...

我尝试了多种方法来获取坐标周围的命中列表,但无济于事:
$ curl -XGET http://localhost:9200/test-index/dev/_search -d '
{           
"filter" : { 
      "geo_distance" : {
       "distance" : "20km",
                    “Coordinates : {
                        "lat" : 40.00,
                        "lon" : 9.00
                    }
                }
            }
        }
'

这是可悲的结果:
"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[6W3CA5U5TqStabDolHcIng][test-index][0]: SearchParseException[[test-index][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [\n{\n\"filter\" : {\n      \"geo_distance\" : {\n       \"distance\" : \"20km\",\n                    “Coordinates : {\n                        \"lat\" : 40.00,\n                        \"lon\" : 9.00\n                    }\n                }\n            }\n        }\n]]]; nested: QueryParsingException[[test-index] failed to find geo_point field [“Coordinates]]; }{[6W3CA5U5TqStabDolHcIng][test-index][1]: SearchParseException[[test-index][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [\n{\n\"filter\" : {\n      \"geo_distance\" : {\n       \"distance\" : \"20km\",\n                    “Coordinates : {\n                        \"lat\" : 40.00,\n                        \"lon\" : 9.00\n                    }\n                }\n            }\n        }\n]]]; nested: QueryParsingException[[test-index] failed to find geo_point field [“Coordinates]]; }{[6W3CA5U5TqStabDolHcIng][test-index][2]: SearchParseException[[test-index][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [\n{\n\"filter\" : {\n      \"geo_distance\" : {\n       \"distance\" : \"20km\",\n                    “Coordinates : {\n                        \"lat\" : 40.00,\n                        \"lon\" : 9.00\n                    }\n                }\n            }\n        }\n]]]; nested: QueryParsingException[[test-index] failed to find geo_point field [“Coordinates]]; }{[6W3CA5U5TqStabDolHcIng][test-index][3]: SearchParseException[[test-index][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [\n{\n\"filter\" : {\n      \"geo_distance\" : {\n       \"distance\" : \"20km\",\n                    “Coordinates : {\n                        \"lat\" : 40.00,\n                        \"lon\" : 9.00\n                    }\n                }\n            }\n        }\n]]]; nested: QueryParsingException[[test-index] failed to find geo_point field [“Coordinates]]; }{[6W3CA5U5TqStabDolHcIng][test-index][4]: SearchParseException[[test-index][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [\n{\n\"filter\" : {\n      \"geo_distance\" : {\n       \"distance\" : \"20km\",\n                    “Coordinates : {\n                        \"lat\" : 40.00,\n                        \"lon\" : 9.00\n                    }\n                }\n            }\n        }\n]]]; nested: QueryParsingException[[test-index] failed to find geo_point field [“Coordinates]]; }]","status":400}

有什么帮助吗?

最佳答案

作为错误统计信息,ES无法找到类型为Coordinatesgeo_point字段。您需要将 map Coordinates字段作为geo_point来执行任何位置查询。

{
  "test-index": {
    "mappings": {
      "dev": {
        "properties": {
          "Coordinates": {
            "type": "geo_point"  <--- change type from double to geo_point
          },
          "DisplayName": {
            "type": "string"
          },
          "Location": {
            "type": "string"
          },
          "RawLocation": {
            "type": "string"
          },
          "Reputation": {
            "type": "string"
          }
        }
      }
    }
  }
}

由于您使用的是array format,因此需要将坐标插入为[lon, lat]

您将不得不reindex您的数据。之后,您的查询将起作用。

希望这可以帮助!

关于rest - Elasticsearch:地理位置距离查询错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35120066/

相关文章:

android - 错误 - 导入谷歌播放服务

c# - 将 REST 响应转换为 XDocument 时出现问题

Java-rest 调用 : Population of value within variable should work for two variables name

scala - 将Kibana中字段的映射从String更改为Double

elasticsearch - 将自定义分析器添加到使用 spring 构建的索引的基础知识

linux - 从linux中的某个目录启动shell

rest - Keycloak 服务到服务

PowerShell 获取带有正文的请求

elasticsearch - 自动生成弹性指数文档的工具

android - onLocationChanged 永远不会被调用 Emulator