我需要在elasticsearch中使用java API索引MultiPolygon对象。我已经为它创建了映射。
jsonBuilder.startObject("geom")
.field("type", "geo_shape")
.field("tree", "quadtree")
.field("precision", "1m")
.endObject()
但我不知道索引 MultiPolygon 对象的简单方法。我知道http方式。
{
"location" : {
"type" : "multipolygon",
"coordinates" : [
[[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],
[[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],
[[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]
]
}
}
有人可以帮我解决这个问题吗?我真的很感激。
海龙
最佳答案
使用从 jsonBuilder()
返回的 XContentBuilder
手动构建它。
jsonBuilder()
.startObject()
.startObject("location")
.field("type", "multipolygon")
.startArray()
.startArray()
.startArray().value(102.0).value(2.0).endArray()
// add the rest of the coordinates here as more arrays
...
.endArray()
.endArray()
.endObject()
.endObject();`
jsonBuilder()
可作为 org.elasticsearch.common.xcontent.XContentFactory
中的静态导入使用。
构建完成后,请使用此处描述的 Index API 对其进行索引: https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/index_.html
关于java - 如何在elasticsearch中使用java API索引vividsolutions MultiPolygon对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21636513/