如何使用Java API设置Ingest attachment(elasticsearch)插件选项?

问题描述 投票:1回答:1

我在弹性搜索中使用Ingest Attachment Processor Plugin。我需要使用Java API设置附件选项(indexed_charspropertiesignore_missing等)。我怎样才能做到这一点?

我正在创建索引和设置管道,如下所示:

String id = ...
Map<String, Object> row = ...
client.prepareIndex(indexName, "my_type", id)
                    .setSource(row)
                    .setPipeline("my_pipeline")
                    .execute();
java elasticsearch elasticsearch-plugin java-api
1个回答
1
投票

我找到了答案,如果你有嵌套文件你必须使用foreach else build json就像documentation

文献:

解:

try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
    BytesReference pipelineSource = jsonBuilder.startObject()
            .field("description", "Extract attachment information")
            .startArray("processors")
              .startObject()
                .startObject("foreach")
                  .field("field", "my_field")
                  .startObject("processor")
                    .startObject("attachment")
                      .field("field", "_ingest._value.my_base64_field")
                      .field("target_field", "_ingest._value.my_base64_field")
                      .field("ignore_missing", true)
                      .field("indexed_chars", -1)
                    .endObject()
                  .endObject()
                .endObject()
              .endObject()
            .endArray()
            .endObject().bytes();
    client.admin().cluster().preparePutPipeline("my_pipeline",
            pipelineSource, XContentType.JSON).get();
}

要么

你可以手动放在json下面

结果:

http://localhost:9200/_ingest/pipeline/my_pipeline

{
  "my_pipeline": {
    "description": "Extract attachment information",
    "processors": [
      {
        "foreach": {
          "field": "my_field",
          "processor": {
            "attachment": {
              "field": "_ingest._value.my_base64_field",
              "target_field": "_ingest._value.my_base64_field",
              "ignore_missing": true,
              "indexed_chars": -1
            }
          }
        }
      }
    ]
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.