简体   繁体   English

如何在 Java 中使用 Elasticsearch Ingest 附件处理器插件

[英]How to use Elasticsearch Ingest Attachment Processor Plugin in Java

I am looking for a way to use the Ingest Attachment Processor Plugin from the Java High-level REST client.我正在寻找一种方法来使用来自 Java 高级 REST 客户端的摄取附件处理器插件

It seems that you need to do two steps, ie, first you define a pipeline containing the attachment processor (eg, referring to a field data and using a pipeline id attachment )看起来你需要做两个步骤,即首先你定义一个包含附件处理器的管道(例如,引用一个字段数据并使用一个管道 id附件

PUT _ingest/pipeline/attachment
{
  "description" : "Extract attachment information",
  "processors" : [
    {
      "attachment" : {
        "field" : "data"
      }
    }
 ]
}

then you PUT data referring to the field (here data ) and the pipeline (here attachment )然后你 PUT 数据指的是字段(这里是data )和管道(这里是附件

PUT my_index/my_type/my_id?pipeline=attachment
{
  "data": "e1xydGYxXGFuc2kNCkxvcmVtIGlwc3VtIGRvbG9yIHNpdCBhbWV0DQpccGFyIH0="
}

Now I want to execute these two steps from the Java High-level REST client.现在我想从 Java 高级 REST 客户端执行这两个步骤。 It seems that I can execute the first step (definition of the pipeline) with the Put Pipeline API , but I could not find a Java mechanisms for the second part, ie, writing the actual data while referring to the pipeline.似乎我可以使用Put Pipeline API执行第一步(定义管道),但是我找不到第二部分的 Java 机制,即在引用管道的同时写入实际数据。

In a Java high-level REST client there is a method to index using IndexRequest , during the creation of it, you could set pipeline via Java method.在 Java 高级 REST 客户端中,有一种使用IndexRequest进行索引的方法,在创建它的过程中,您可以通过 Java 方法设置管道。

JavaDoc reference for it - https://artifacts.elastic.co/javadoc/org/elasticsearch/elasticsearch/7.6.2/org/elasticsearch/action/index/IndexRequest.html?is-external=true#setPipeline(java.lang.String)它的 JavaDoc 参考 - https://artifacts.elastic.co/javadoc/org/elasticsearch/elasticsearch/7.6.2/org/elasticsearch/action/index/IndexRequest.html?is-external=true#setPipeline(java.lang 。细绳)

I would expect to have code like this:我希望有这样的代码:

RestHighLevelClient client = new RestHighLevelClient(
        RestClient.builder(new HttpHost("localhost", 9200, "http")));

final IndexRequest indexRequest = new IndexRequest("index-name", "index-type");
indexRequest.setPipeline("pipeline-name");

Map<String, Object> jsonMap = new HashMap<>();
jsonMap.put("data", "e1xydGYxXGFuc2kNCkxvcmVtIGlwc3VtIGRvbG9yIHNpdCBhbWV0DQpccGFyIH0=");

indexRequest.source(jsonMap);
final IndexResponse indexResponse = client.index(indexRequest);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM