【ElasticSearch】检索word pdf插件ingest attachment的管道配置
创始人
2024-05-20 12:27:56
0次

文章目录

  • 单附件:
    • 1.创建管道single_attachment
      • 定义文本抽取管道
    • 2.创建index
      • 创建索引库
    • 3.索引数据
      • 插入word文档
    • 4.查询
      • 查询所有
  • 多附件:
    • 1.创建管道single_attachment
      • 定义文本抽取管道-多附件
    • 2.创建index
      • 创建知识库索引 - 多附件
    • 3.索引数据
      • 插入word文档 - 多附件
    • 4.查询
      • 查询所有
      • 查询结果:

单附件:

1.创建管道single_attachment

定义文本抽取管道

PUT /_ingest/pipeline/attachment
{"description": "Extract attachment information","processors": [{"attachment": {"field": "content","ignore_missing": true}},{"remove": {"field": "content"}}]
}

2.创建index

创建索引库

PUT /knowbase
{"mappings": {"properties": {"esId": {"type": "keyword"},"assortId": {"type": "long"},"title":{"type": "text","analyzer": "ik_max_word","copy_to": "all"},"articleContent":{"type": "text","analyzer": "ik_max_word","copy_to": "all"},"viewNum": {"type": "long"},"version": {"type": "long"},"label": {"type": "keyword"},"code": {"type": "keyword"},"tenantId": {"type": "keyword"},"releaseTime": {"type": "date"},"createBy": {"type": "keyword","index": false},"createTime": {"type": "date"},"all":{"type": "text","analyzer": "ik_max_word"},"attachment": {"properties": {"content":{"type": "text","analyzer": "ik_smart","copy_to": "all"}}}}}
}

3.索引数据

插入word文档

POST /knowbase/_doc?pipeline=attachment
{"name":"知识库文档2.0",
"type":"word",
"content":"文档base64编码"}

另:文件转base64编码 base64.guru。

4.查询

查询所有

GET /knowbase/_search
{"query": {"match_all": {}}
}

多附件:

1.创建管道single_attachment

定义文本抽取管道-多附件

PUT /_ingest/pipeline/attachment
{"description": "Extract attachment information","processors": [{"foreach": {"field": "attachments","processor": {"attachment": {"field": "_ingest._value.content","target_field": "_ingest._value.attachment","remove_binary": true}}}}]
}

需要注意的是,多附件的情况下,field 和 target_field 必须要写成 _ingest._value.*,否则不能匹配正确的字段。
从 es 8.0 版本开始,需要删除二进制文件内容,只需要为 attachment 添加一个属性 remove_binary 为 true,就不需要像上面那样单独写一个 remove 处理器了。

2.创建index

创建知识库索引 - 多附件

PUT /knowbase
{"mappings": {"properties": {"esId": {"type": "keyword"},"assortId": {"type": "long"},"title": {"type": "text","analyzer": "ik_max_word","copy_to": "all"},"articleContent": {"type": "text","analyzer": "ik_max_word","copy_to": "all"},"viewNum": {"type": "long"},"version": {"type": "long"},"label": {"type": "keyword"},"code": {"type": "keyword"},"tenantId": {"type": "keyword"},"releaseTime": {"type": "date"},"createBy": {"type": "keyword","index": false},"createTime": {"type": "date"},"all": {"type": "text","analyzer": "ik_max_word"},"attachments": {"properties": {"attachment": {"properties": {"content":{"type": "text","analyzer": "ik_smart","copy_to": "all"}}}}}}}
}

3.索引数据

插入word文档 - 多附件

POST /knowbase/_doc?pipeline=attachment
{"name":["知识库文档2.0","test知识库文档2.0"],
"type":"word",
"attachments":[{"content":"文档base64编码"},[{"content":"文档base64编码"}]
}

4.查询

查询所有

GET /knowbase/_search
{"query": {"match_all": {}}
}

查询结果:

{"took": 0,"timed_out": false,"_shards": {"total": 1,"successful": 1,"skipped": 0,"failed": 0},"hits": {"total": {"value": 1,"relation": "eq"},"max_score": 1,"hits": [{"_index": "knowbase","_id": "KYfN9oUBJjbl-1BDeeXL","_score": 1,"_source": {"name": ["知识库文档2.0","test知识库文档2.0"],"attachments": [{"attachment": {"date": "2023-01-28T02:12:00Z","content_type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document","author": "tong shaoqing","modifier": "tong shaoqing","modified": "2023-01-28T02:12:00Z","language": "lt","content": """文档内容""","content_length": 30}},{"attachment": {"date": "2023-01-28T02:12:00Z","content_type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document","author": "tong shaoqing","modifier": "tong shaoqing","modified": "2023-01-28T02:12:00Z","language": "lt","content": """文档内容""","content_length": 30}}],"type": "word"}}]}
}

参考:

https://blog.csdn.net/catoop/article/details/124611260
https://www.jianshu.com/p/774e5ed120ba

相关内容

热门资讯

前端-session、jwt 目录:   (1)session (2&#x...
linux入门---制作进度条 了解缓冲区 我们首先来看看下面的操作: 我们首先创建了一个文件并在这个文件里面添加了...
关于测试,我发现了哪些新大陆 关于测试 平常也只是听说过一些关于测试的术语,但并没有使用过测试工具。偶然看到编程老师...
前缀和与对数器与二分法 1. 前缀和 假设有一个数组,我们想大量频繁的去访问L到R这个区间的和,...
nodejs:本地安装nvm实... 一、背景-使用不同版本node的原因 vue3+ts、nuxt3版本,node...
JAVA集合知识整理 Java集合知识整理 HashMap相关 HashMap的底层数据结构:jdk1.8之...
无刷直流电机介绍及单片机控制实... 无刷直流电机介绍及单片机控制实例前言基本概念优势与劣势使用寿命基本结构使用单片机控制实例电子调速器&...
fwdiary(2) dp2 1.传纸条  AcWing 275. 传纸条 - AcWing 走两条路,走一条最大的...
常用的DOS命令 常用的DOS命令 DOS(Disk Operating System,磁...
<C++> 类和对象(下) 1.const成员函数将const修饰的“成员函数”称之为const成员函数,cons...