我是Elasticsearch的新手。我正在尝试使用Java elasticsearch-rest-high-level-client 版本 6.4.0 将 geo_shape 数据添加到我的Elasticsearch索引中
这是我的索引映射
{
"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 ]
]]
}
}
如果我从Kibana Dev Tools控制台 POST 将此数据正常运行。
我正在尝试从Java发布
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: '{']
答案 0 :(得分:1)
似乎您的字符串化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]]]}}"