简体   繁体   English

使用弹性搜索Java客户端时,如何上传pdf到elasticsearch?

[英]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项目 ,以防它解决了您想做的事情。

Here is four options that you can use to index PDFs to ElasticSearch 您可以使用以下四个选项将PDF索引到ElasticSearch

  • Ingest Attachment Plugin 摄取附件插件
  • Apache Tika 阿帕奇·蒂卡(Apache Tika)
  • FsCrawler FsCrawler
  • Ambar 安巴

Pros/cons described in this post 这篇文章中描述的优点/缺点

暂无
暂无

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

相关问题 如何使用Java客户端更新Elastic Search上的条目 - How to update an entry on Elastic Search using Java client 如何使用 AWS CLI 2 将更新的 JAR 上传到现有的 Java Elastic Beanstalk 实例? - How do I upload an updated JAR to an existing Java Elastic Beanstalk instance using the AWS CLI 2? matchQuery elasticsearch:如何使用java在弹性搜索中搜索字符串列表(通配符) - matchQuery elasticsearch : How to search list of strings(wildcard) in elastic search using java 如何在java中使用jest客户端在elasticsearch中编写搜索代码 - how to write code for search in elasticsearch using jest client in java 如何使用 Java 库 (QueryBuilder) 组合多个过滤器查询和 Elastic Search 应该 - How do I combine multiple filter query and should of Elastic Search using Java Library (QueryBuilder) 如何在不使用Elasticsearch库的情况下将数据从Java应用程序发送到Elastic Search - How to send data from a java application to elastic search without using the elasticsearch libraries 如何通过 Java 高级 rest 客户端在 Elastic Search 中使用多个字段进行搜索 - How to search using multiple fields in Elastic Search through Java high level rest client 如何将 PutMappingRequest 与 Elasticsearch 8 Java API 客户端一起使用? - How do I use PutMappingRequest with the Elasticsearch 8 Java API Client? 如何使用带有列表作为参数的java api在elasticsearch上进行搜索 - How to do search on elasticsearch using java api with a list as parameter 如何使用 JAVA 高级 REST 客户端创建弹性搜索索引? - How can I create an elastic search index with the JAVA high level REST client?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM