【发布时间】:2016-08-23 02:47:23
【问题描述】:
我在 Elasticsearch 中存储了一些文档,每个文档都包含一个坐标数组,用于在 Google 地图上绘制一条线。在这些文档上,我想做一个地理边界框查询,以了解哪些与用户在地图上查看的位置相关。 当我尝试这样做时,我收到错误“无法派生 xcontent”。
这是一个文档的外观示例(可以包含数百个坐标):
{
"type" : "Feature",
"properties" : {
"Type" : "Path",
"Name" : "An example line"
},
"geometry" : {
"type" : "LineString",
"coordinates" : [ [ 14.998659698781326, 59.83282967919488 ], [ 14.998221382378132, 59.832346163020866 ], [ 14.997889000000002, 59.83210100000001 ], [ 14.997201215918253, 59.83165390720879 ], [ 14.996313, 59.83200200000001 ] ]
}
}
这是我使用 curl 运行的查询(为了可读性而进行了美化,否则在一行中没有空格):
curl.exe http://11.11.111.111:9200/map/path/_search?pretty -d'
{
"query": {
"geo_bounding_box": {
"location": {
"top_left": {
"lat": 60.50,
"lon": 14.30
},
"bottom_right": {
"lat": 59.86,
"lon": 16.06
}
}
}
}
}'
这是来自上述查询的响应:
{
"error" : {
"root_cause" : [ {
"type" : "parse_exception",
"reason" : "Failed to derive xcontent"
} ],
"type" : "search_phase_execution_exception",
"reason" : "all shards failed",
"phase" : "query",
"grouped" : true,
"failed_shards" : [ {
"shard" : 0,
"index" : "map",
"node" : "ye2EayFlRFCM6xGWjzcfwQ",
"reason" : {
"type" : "parse_exception",
"reason" : "Failed to derive xcontent"
}
} ]
},
"status" : 400
}
这是在 Elasticsearch 中找到的日志:
[2016-07-31 10:23:10,268][DEBUG][action.search ] [one] [map][2], node[ye2EayFlRFCM6xGWjzcfwQ], [P], v[2], s[STARTED], a[id=Ptvmzu-2R6WHH89BLifz6g]: Failed to execute [org.elasticsearch.action.search.SearchRequest@866697a] lastShard [true]
RemoteTransportException[[one][10.3.0.4:9300][indices:data/read/search[phase/query]]]; nested: SearchParseException[failed to parse search source [_na_]]; nested: ElasticsearchParseException[Failed to derive xcontent];
Caused by: SearchParseException[failed to parse search source [_na_]]; nested: ElasticsearchParseException[Failed to derive xcontent];
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:855)
at org.elasticsearch.search.SearchService.createContext(SearchService.java:654)
at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:620)
at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:371)
at org.elasticsearch.search.action.SearchServiceTransportAction$SearchQueryTransportHandler.messageReceived(SearchServiceTransportAction.java:368)
at org.elasticsearch.search.action.SearchServiceTransportAction$SearchQueryTransportHandler.messageReceived(SearchServiceTransportAction.java:365)
at org.elasticsearch.transport.TransportRequestHandler.messageReceived(TransportRequestHandler.java:33)
at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:75)
at org.elasticsearch.transport.TransportService$4.doRun(TransportService.java:376)
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
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: ElasticsearchParseException[Failed to derive xcontent]
at org.elasticsearch.common.xcontent.XContentFactory.xContent(XContentFactory.java:240)
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:824)
JSON 本身验证为正确。其他查询正常工作,我可以通过 ID 获取特定的查询并检索所有查询。只有这个查询给我带来了一些麻烦。
我已经尝试使用过滤器进行查询,就像在documentations 页面上一样,但这也不起作用,给出了与我上面提到的相同的错误。 我在 Linux 上使用 Elasticsearch 2.3.1。
需要什么才能使这个查询起作用?在这种情况下,“无法派生 xcontent”错误是什么意思,我该如何解决?
【问题讨论】:
-
与您面临的问题无关,但
geo_bounding_box仅适用于地理点,不适用于地理形状。 -
文档确实说“过滤器可以与每个文档的多个位置/点一起使用。一旦单个位置/点与过滤器匹配,文档将被包含在过滤器中”。线串本质上是一堆点,通过这些点绘制一条线,还是我误解了?
-
我相信你误解了。你可以有一个点数组,这与一条线不同。
-
在这种情况下,您知道我应该使用什么来代替执行此查询吗?
-
geo_shape是更灵活的地理查询/过滤器,适用于geo_shape数据类型。
标签: elasticsearch bounding-box