我正在为我的应用程序使用Elasticsearch。因为我试图为给定的lat运行空间查询,但是我无法获得结果....
我的索引如下:
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "pca_beta_v1",
"_type": "place",
"_id": "8neiQuwqTMmCLPo7Yu6TxA",
"_score": 1,
"_source": {
"idmap70": 305215,
"id_0": 356,
"id_1": "33",
"id_2": "602222",
"id_3": "566693",
"id_4": "628343548",
"name_0": "India",
"name_1": "aaaaa",
"name_2": "bbbb",
"name_3": "cccc",
"name_4": "nnnnnn",
"latitude": 13.534991,
"longitude": 80.015182,
"key": "ooooooo",
"leveltype": "ttttt"
}}]
}
我尝试了以下查询:
GET bdrtfd/_search/
{
"query": {
"match_all": {}
},
"filter": {
"geo_distance": {
"location": {
"lat": "13.534991",
"lon": "80.015182"
},
"distance": "3km"
}
}
}
但是我收到了错误:
{
"error": "SearchPhaseExecutionException[Failed to execute phase [query_fetch], all shards failed; shardFailures {[pPP8DQK9QASt8h9RUKAmsQ][pca_beta_v1][0]: SearchParseException[[pca_beta_v1][0]: query[ConstantScore(*:*)],from[-1],size[-1]: Parse Failure [Failed to parse source [{\n \"query\": {\n \"match_all\": {}\n },\n \"filter\": {\n \"geo_distance\": {\n \"location\": {\n \"lat\": \"13.534991\",\n \"lon\": \"80.015182\"\n },\n \"distance\": \"3km\"\n }\n }\n}\n]]]; nested: QueryParsingException[[pca_beta_v1] failed to find geo_point field [location]]; }]",
"status": 400
}
答案 0 :(得分:0)
映射中的"latitude": 13.534991, "longitude": 80.015182
字段需要具有不同类型才能在地理位置计算中使用。它只需要一个字段,而不是两个字段,它必须是这样的:
"location": {
"type": "geo_point"
}
然后,在编制索引时,您可以指定以下内容:
{"location":{"lat":13.534991,"lon":80.015182}}
然后你的查询就可以了。