我在elasticsearch上使用摄取附件处理器插件。我需要使用Java API设置附件选项。我该怎么办?
我正在创建索引并设置管道,如下所示:
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.
}
我在使用.admin()
方法时遇到问题。
`.admin()` is undefined for the type RestHighLevelClient
我可以使用哪种方法代替.admin()
方法。