将 geo_shape 数据添加到 elasticsearch

Adding geo_shape data to elasticsearch

我是 Elasticsearch 的新手。我正在尝试使用 Java elasticsearch-rest-high-level-clientgeo_shape 数据添加到我的 Elasticsearch 索引版本 6.4.0

这是我的索引映射

{
  "elktest": {
    "mappings": {
      "test": {
        "properties": {
          "Location": {
            "type": "geo_shape"
          }
        }
      }
    }
  }
}

我正在尝试将此数据添加到索引中

{
  "Location" : {
    "type": "polygon", 
   "coordinates" : [[ 
        [ -104.04405,45.01967 ],
        [ -111.03084,44.99904 ],
        [ -111.04131,41.011   ],
        [ -104.03375,41.00193 ],
        [ -104.04405,45.01967 ]
        ]]
  }
}

如果我 POST 来自 Kibana Dev Tools 控制台的数据它工作正常。

来自 Java,我正在尝试 POST

String jsonString = "{\"Location\":\"{type: geo_polygon, coordinates:    [[             [ -105.04405,47.01967 ],        [ -111.03084,44.99904 ],        [ -111.04131,41.011   ],        [ -104.03375,41.00193 ],        [ -105.04405,47.01967 ]]] }\"}";

IndexRequest request = new IndexRequest(indexName, indexType, 100);
request.source(jsonString, XContentType.JSON);
IndexResponse indexResponse = client.index(request, RequestOptions.DEFAULT);


我遇到了这个异常

Elasticsearch exception [type=mapper_parsing_exception, reason=failed to parse [Location]]
Elasticsearch exception [type=parse_exception, reason=expected word but found: '{']

您的字符串化 JSON 似乎有误。这里有一个额外的"

                         here ------v
String jsonString = "{\"Location\":\"{type: ...

从浏览器的控制台

JSON.stringify({
  "Location" : {
    "type": "polygon", 
   "coordinates" : [[ 
        [ -104.04405,45.01967 ],
        [ -111.03084,44.99904 ],
        [ -111.04131,41.011   ],
        [ -104.03375,41.00193 ],
        [ -104.04405,45.01967 ]
        ]]
  }
})
# additional escaping needs to be done but ...
"{"Location":{"type":"polygon","coordinates":[[[-104.04405,45.01967],[-111.03084,44.99904],[-111.04131,41.011],[-104.03375,41.00193],[-104.04405,45.01967]]]}}"