我正在尝试将 geo_point 用于距离,但它始终显示位置类型为 double 而不是 geo_point 如何设置映射到 geo_point 的位置。
实际上我必须找到 5km 范围内的所有记录。
"pin" : {
"properties" : {
"location" : {
"properties" : {
"lat" : {
"type" : "double"
},
"lon" : {
"type" : "double"
}
}
},
"type" : {
"type" : "string"
}
}
},
当我尝试使用下面的查询进行搜索以查找距离德里 lat long 5 公里以内的结果时:
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"pin": {
"distance": "5",
"distance_unit": "km",
"coordinate": {
"lat": 28.5402707,
"lon": 77.2289643
}
}
}
}
}
}
它向我显示错误 query_parsing_exception 和没有为 [pin] 注册的查询。我无法弄清楚问题所在。它总是抛出这个异常
{
"error": {
"root_cause": [
{
"type": "query_parsing_exception",
"reason": "No query registered for [pin]",
"index": "find_index",
"line": 1,
"col": 58
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "find_index",
"node": "DtpkEdLCSZCr8r2bTd8p5w",
"reason": {
"type": "query_parsing_exception",
"reason": "No query registered for [pin]",
"index": "find_index",
"line": 1,
"col": 58
}
}
]
},
"status": 400
}
请帮我解决这个问题。我如何设置 geo_point 并解决此异常错误和状态 400 和 all_shards_failed 错误
最佳答案
你只需要像这样映射你的 pin
类型,即使用 geo_point
data type :
# 1. first delete your index
DELETE shouut_find_index
# 2. create a new one with the proper mapping
PUT shouut_find_index
{
"mappings": {
"search_shouut": {
"properties": {
"location": {
"type": "geo_point"
},
"type": {
"type": "string"
}
}
}
}
}
然后你可以像这样索引一个文档
PUT shouut_find_index/search_shouut/1
{
"location": {
"lat": 28.5402707,
"lon": 77.2289643
},
"type": "dummy"
}
最后你的查询看起来像这样
POST shouut_find_index/search_shouut/_search
{
"query": {
"filtered": {
"filter": {
"geo_distance": {
"distance": "5km",
"location": {
"lat": 28.5402707,
"lon": 77.2289643
}
}
}
}
}
}
关于php - Elasticsearch 地理点查询过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36997597/