ElasticSearch SearchParseException:使用geo_distance过滤器时解析失败[无法解析源]

时间:2017-02-28 08:25:21

标签: elasticsearch elasticsearch-plugin

我是ElasticSeach的新手,我已经在弹性群集中索引了一系列城市。每个城市都包含城市,州,地点(纬度和长度)等详细信息。

现在我的要求是搜索特定地点20公里范围内的城市,我正在通过纬度和特定城市的城市已被索引到集群中。

以下是我在弹头搜索头部插件的UI中显示的索引数据:

{
    "_index": "us_large_cities",
    "_type": "city",
    "_id": "AVqDpwkjfjWoT7yVe_qt",
    "_version": 1,
    "_score": 1,
    "_source": {
        "city": "Lincoln",
        "state": "NE",
        "location": {
            "lat": "40.8000011",
            "lon": "-96.6669599"
         }
     }
} 

这是我用于搜索数据的curl命令:

curl -XGET 'http://localhost:9200/us_large_cities/city/_search?pretty=true' -d '
{
  "query": {
    "filtered" : {
        "query" : {
            "match_all" : {}
        },
        "filter" : {
            "geo_distance" : {
                "distance" : "20km",
                "location" : {
                    "lat" : 40.8000011,
                    "lon" : -96.6669599
                }
            }
        }
    }
  }
}'

我得到了SearchParseException,这里是完整的堆栈跟踪:

org.elasticsearch.search.SearchParseException: [us_large_cities][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [
{
  "query": {
    "filtered" : {
        "query" : {
            "match_all" : {}
        },
        "filter" : {
            "geo_distance" : {
                "distance" : "20km",
                "location" : {
                    "lat" : 40.8000011,
                    "lon" : -96.6669599
                }
            }
        }
    }
  }
}]]
    at org.elasticsearch.search.SearchService.parseSource(SearchService.java:687)
    at org.elasticsearch.search.SearchService.createContext(SearchService.java:543)
    at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:515)
    at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:277)
    at org.elasticsearch.search.action.SearchServiceTransportAction$5.call(SearchServiceTransportAction.java:231)
    at org.elasticsearch.search.action.SearchServiceTransportAction$5.call(SearchServiceTransportAction.java:228)
    at org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:559)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.elasticsearch.index.query.QueryParsingException: [us_large_cities] failed to find geo_point field [location]
    at org.elasticsearch.index.query.GeoDistanceFilterParser.parse(GeoDistanceFilterParser.java:159)
    at org.elasticsearch.index.query.QueryParseContext.executeFilterParser(QueryParseContext.java:347)
    at org.elasticsearch.index.query.QueryParseContext.parseInnerFilter(QueryParseContext.java:328)
    at org.elasticsearch.index.query.FilteredQueryParser.parse(FilteredQueryParser.java:74)
    at org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:281)
    at org.elasticsearch.index.query.IndexQueryParserService.innerParse(IndexQueryParserService.java:382)
    at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:281)
    at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:276)
    at org.elasticsearch.search.query.QueryParseElement.parse(QueryParseElement.java:33)
    at org.elasticsearch.search.SearchService.parseSource(SearchService.java:671)
    ... 9 more

我搜索了SO中可能出现的各种帖子,但没有一个对我有用。 我有错误的任何建议吗?

1 个答案:

答案 0 :(得分:0)

[us_large_cities] failed to find geo_point field [location]

这是您的错误,因为如果您要使用geo_distance过滤器,则必须将位置字段编入索引为geo_point字段。更多信息here

编辑:所以

"location": {
            "lat": "40.8000011",
            "lon": "-96.6669599"
         }

需要定义为:

{
    "city_location" : {
        "location" : {
            "lat" : 41.12,
            "lon" : -71.34
        }
    }
}