java - 如何在elasticsearch中使用java API索引vividsolutions MultiPolygon对象?

标签 java elasticsearch

我需要在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/

相关文章:

Java:使用 Scanner 和 PrintWriter 读取 int 值并将其写入文件

带锁的Java多线程同步

java - 从标准输入中查找三个 double 中的最大值

php - Cakephp3 ElasticSearch查询Q

java - 在 JApplet 中正确使用事件调度线程?

java - SSL 异常 : "received close_notify during handshake" upon initializing Alexa Skill Management API (SMAPI)

elasticsearch - 如果不是默认的,如何检查 Elasticsearch 中的刷新间隔

elasticsearch - ElasticSearch:如果索引的运行状况为 'red'是什么意思?

mongodb - 使用Logstash JDBC插件同步MongoDB和Elasticsearch时避免重复

docker - 将Elasticsearch日志迁移到其他集群