[英]How do I upload a pdf to elasticsearch when using the elastic search java client?
This link explains how to use the REST API to upload an attachment. 此链接说明了如何使用REST API上传附件。
But I want to upload an attachment with the java client... 但是我想用Java客户端上传附件...
I assume the following classes are relevant (though I may be wrong)... 我认为以下课程是相关的(尽管我可能错了)...
org.elasticsearch.ingest.IngestService
org.elasticsearch.ingest.PipelineStore
I realize that I can just fall back to the REST interface but I'd rather try and use the native client first... 我意识到我可以回到REST接口,但是我想先尝试使用本机客户端...
Just send a BASE64 encoded PDF in a field like: 只需在以下字段中发送BASE64编码的PDF:
String base64;
try (InputStream is = YourClass.class.getResourceAsStream(pathToYourFile)) {
byte bytes[] = IOUtils.toByteArray(is);
base64 = Base64.getEncoder().encodeToString(bytes);
}
IndexRequest indexRequest = new IndexRequest("index", "type", "id")
.setPipeline("foo")
.source(
jsonBuilder().startObject()
.field("field", base64)
.endObject()
);
In case you are not aware of it, I'm also linking to FSCrawler project in case it solves something you want to do already. 如果您不知道它,我还将链接到FSCrawler项目 ,以防它解决了您想做的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.