I'm using Ingest Attachment Processor Plugin on elasticsearch. I need to set attachment optionswith Java API. How can I do that?
I am creating index and setting pipeline like below:
RestHighLevelClient restHighLevelClient = null;
File file = new File(filePath);
try {
FileInputStream fileInputStreamReader = new FileInputStream(file);
byte[] bytes = new byte[(int) file.length()];
fileInputStreamReader.read(bytes);
encodedfile = new String(Base64.getEncoder().encodeToString(bytes));
//System.out.println(encodedfile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
if (restHighLevelClient != null) {
restHighLevelClient.close();
}
} catch (final Exception e) {
System.out.println("Error closing ElasticSearch client: ");
}
try {
restHighLevelClient = new RestHighLevelClient(RestClient.builder(new HttpHost("localhost", 9200, "http"),
new HttpHost("localhost", 9201, "http")));
} catch (Exception e) {
System.out.println(e.getMessage());
}
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();
restHighLevelClient.admin().cluster().preparePutPipeline("my_pipeline",
pipelineSource, XContentType.JSON).get(); //throwing error on this line.
}
Am facing an issue in using .admin()
method.
`.admin()` is undefined for the type RestHighLevelClient
Which method i can use instead of .admin()
method.