Elasticsearch geo_bounding_box无法派生xcontent

时间:2016-07-31 17:57:21

标签: elasticsearch bounding-box

我在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"在这种情况下意味着什么,我该如何解决?

1 个答案:

答案 0 :(得分:1)

如果其他人有同样的问题,这是我找到的解决方案。 在卷曲查询中,我写了-d'[JSON]'并简单地删除'围绕[JSON]做了伎俩。现在Elasticsearch可以读取查询。 我已经开始尝试使用geo_shape查询作为pickypg建议。

CORRECT: -d [JSON] 
INCORRECT: -d '[JSON]'