2

I am looking for a way to use the Ingest Attachment Processor Plugin from the Java High-level REST client.

It seems that you need to do two steps, i.e., first you define a pipeline containing the attachment processor (e.g., referring to a field data and using a pipeline id attachment)

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 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. 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, i.e., writing the actual data while referring to the pipeline.

1 Answer 1

1

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.

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)

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);
Sign up to request clarification or add additional context in comments.

2 Comments

Looking for this answer from 2 days. Thanks. It worked, Can you tell me how to upload bulk documents at a time

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.