elasticsearch 为什么我不能在弹性搜索中按地理位置查询?
所以我正在尝试ElasticSearch,这就是我所做的 1) 在我的索引中添加了一个名为“test”的geo_点映射 2) 为测试中的文档编制索引:elasticsearch 为什么我不能在弹性搜索中按地理位置查询?,elasticsearch,geolocation,elasticsearch,Geolocation,所以我正在尝试ElasticSearch,这就是我所做的 1) 在我的索引中添加了一个名为“test”的geo_点映射 2) 为测试中的文档编制索引: curl -XPUT 'localhost:9200/test/type1/1?pretty' -d '{ "location" : { "lat" : 74, "lon" : 90 }
curl -XPUT 'localhost:9200/test/type1/1?pretty' -d '{
"location" : {
"lat" : 74,
"lon" : 90
}
}'
3) 然后通过地理位置过滤器编写如下查询:
curl -XPOST 'localhost:9200/test2/_search?pretty' -d '{
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "200km",
"location" : {
"lat" : 40,
"lon" : -70
}
}
}
}
}'
为此,我得到:
“错误”:“SearchPhaseExecutionException[执行阶段失败
[查询],所有碎片失败;碎片失败
{[QpGEHtdcReeYmt8X2tG26g][test2][0]:
RemoteTransportException[[Jester][inet[/10.58.91.21:9301]][search/phase/query];
嵌套:SearchParseException[[test2][0]:从[-1],大小[-1]:解析
失败[未能分析源[na]];嵌套:
ElasticsearchParseException[未能从中派生xcontent
org.elasticsearch.common.bytes。ChannelBufferBytesReference@60d8bc76])
首先,在您的查询(即第3段代码)中,localhost:9200/test2/\u search?pretty
应该是localhost:9200/test/\u search?pretty
,即您没有查询正确的索引
如果您的查询只是缺少query
关键字(即filtered
应包含在query
中),则应如下所示:
curl -XPOST 'localhost:9200/test/_search?pretty' -d '{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"geo_distance": {
"distance": "200km",
"location": {
"lat": 40,
"lon": -70
}
}
}
}
}
}
你能在没有地理信息的情况下运行简单的查询吗?是的,前两个成功了,但第三个失败了。
curl -XPOST 'localhost:9200/test/_search?pretty' -d '{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"geo_distance": {
"distance": "200km",
"location": {
"lat": 40,
"lon": -70
}
}
}
}
}
}