如何在elasticsearch中使用java API索引多多边形对象?
我需要在elasticsearch中使用JavaAPI索引MultiPolygon对象。我已经为它创建了映射如何在elasticsearch中使用java API索引多多边形对象?,java,elasticsearch,Java,elasticsearch,我需要在elasticsearch中使用JavaAPI索引MultiPolygon对象。我已经为它创建了映射 jsonBuilder.startObject("geom") .field("type", "geo_shape") .field("tree", "quadtree") .field("precision", "1m") .endObject() 但我不知道索引多多边形对象的简单方法。我知道这条路 { "location" : { "type" : "mul
jsonBuilder.startObject("geom")
.field("type", "geo_shape")
.field("tree", "quadtree")
.field("precision", "1m")
.endObject()
但我不知道索引多多边形对象的简单方法。我知道这条路
{
"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()
在org.elasticsearch.common.xcontent.XContentFactory
中作为静态导入提供
构建之后,使用下面描述的索引API对其进行索引:
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();`