使用Elasticsearch Ingest Attachment Processor 插件处理word/pdf文件

洼地云 ai-quyi.png

elasticsearch.jpg

在使用elasticsearch时,如果涉及到Microsoft Office Word文件、PDF文件,可以使用ingest-attachment插件进行处理。

环境

  • Elasticsearch 7.1.1;
  • ingest-attachment-7.1.1;
  • CENTOS 7;

索引文档

Elastcisearch安装ingest-attachment插件的过程参考:Elasticsearch 7安装ingest-attachment插件的两种方式

另外,在CENTOS上,借助perl对base64编码进行处理,有的环境可能没有预装perl,使用sudo yum install -y perl安装即可。

1.创建索引

curl -XPUT 'http://10.47.0.96:9200/data_archives_attachment'

2.创建管道流

curl -H  'Content-Type: application/json' -XPUT 'http://10.47.0.96:9200/_ingest/pipeline/single_attachment' -d'
{
  "description" : "Extract attachment information",
  "processors" : [
    {
      "attachment" : {
        "field": "data",
        "indexed_chars" : -1,
        "ignore_missing" : true
      }
    }
  ]
}'

3.处理docx word文档

curl -H  'Content-Type: application/json' -XPUT 'http://10.47.0.96:9200/data_archives_attachment/_doc/1?pipeline=single_attachment' -d'
{
  "filename": "四个空格-https://www.4spaces.org",
  "data": "'`base64 -w 0 /home/michael/Spring.docx | perl -pe 's/\n/\\n/g'`'"
}'

4.查询结果

curl -H  'Content-Type: application/json' -XGET 'http://10.47.0.96:9200/data_archives_attachment/_doc/1?pretty'

在head插件里查看效果:

elasticsearch-index-word.jpg

这里是每次处理一个文件,如果是每次处理多个文件,参考:使用Elasticsearch Ingest Attachment Processor 插件处理文档

JAVA方式实现:Java实现Elasticsearch对word/pdf文件创建索引

参考:

  1. elasticsearch ingest-attachment 对于 word、pdf等文件内容的索引
  2. Index a MS Office documents to Elasticsearch
赞(0)
未经允许禁止转载:优米格 » 使用Elasticsearch Ingest Attachment Processor 插件处理word/pdf文件

评论 抢沙发

合作&反馈&投稿

商务合作、问题反馈、投稿,欢迎联系

广告合作侵权联系

登录

找回密码

注册