这里写自定义目录标题

  • 1.简介
  • 2.实现步骤

1.简介

ElasticSearch只能处理文本,不能直接处理文档。要实现 ElasticSearch 的附件导入需要以下两个步骤:
一、对多种主流格式的文档进行文本抽取。
二、将抽取出来的文本内容导入 ElasticSearch。

由于 ElasticSearch 是基于 JSON 格式的文档数据库,所以附件文档在插入 ElasticSearch 之前必须进行 Base64 编码。

2.实现步骤

建立自己的文本抽取管道pipeline

1、单文件上传
PUT _ingest/pipeline/simple_attachment
{
“description” : “lhy-单文件管道流”,
“processors”:[
{
“attachment”:{
“field”:“data”,
“indexed_chars” : -1,
“properties”:[“content”, “title”,“content_type”],
“ignore_missing”:true
}
}]
}

2.创建多文件流
PUT _ingest/pipeline/multiple_attachment
{
“description”: “lhy-多文件管道流”
, “processors”: [
{
“foreach”: {
“field”: “attachments”,
“processor”: {
“attachment”: {
“target_field”: “_ingest._value.attachment”,
“field”: “_ingest._value.data”,
“properties”:[“content”, “title”,“content_type”]
}
}
}
}
]
}
3.字段含义:
field : 指定某个字段作为附件内容字段(需要用base64进行加密)
target_field:指定某个字段作为附件信息字段(作者、时间、类型)
indexed_chars : 指定解析文件管道流的最大大小,默认是100000。如果不想限制设置为-1(注意设置为-1的时候如果上传文件过大会而内存不够会导致文件上传不完全)
indexed_chars_field:指定某个字段能覆盖index_chars字段属性,这样子可以通过文件的大小去指定indexed_chars值。
properties: 选择需要存储附件的属性值可以为:content,title,name,author,keyword,date,content_type,content_length,language
ignore_missing: 默认为false,如果设置为true表示,如果上面指定的field字段不存在这不对附件进行解析,文档还能继续保留

导入文档

public void testFileQuery() {
Settings settings = Settings.builder()
.put(“cluster.name”, “my-esLearn”) //连接的集群名
.put(“client.transport.ignore_cluster_name”, true) //如果集群名不对,也能连接
.build();

//创建client
TransportClient  transportClient = new PreBuiltTransportClient(settings)
.addTransportAddress(new TransportAddress(InetAddress.getByName("192.168.1.45"), 9300));
String path = "D:\\testFile\\test.doc"
String contentStr = encryptToBase64(path);
XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject()
.field("id", "java001")
.field("title", "这是我第一个javaAPI")
.field("data", contentStr)
.endObject();
transportClient.prepareIndex("index","doc","java001").setPipeline("simple_attachment")
.setSource(xContentBuilder).get();

}

public String encryptToBase64(String filePath) {
if (filePath == null) {
return null;
}
try {
byte[] b = Files.readAllBytes(Paths.get(filePath));
return Base64.getEncoder().encodeToString(b);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

查询文档
GET /index/doc/_search

[参考] (https://blog.csdn.net/LazyBoy_Z_z/article/details/82865115)
[参考] (https://blog.csdn.net/LazyBoy_Z_z/article/details/82864264)

Elasticsearch 6.4 ingest-attachment对文件IK分词器全文检索相关推荐

  1. Elasticsearch 6.4 ingest-attachment对office文件IK分词器全文检索(1) HttpAPI使用

    这款插件主要是处理ES中文档解析,如果博友们对ES感兴趣欢迎相互交流:(该文默认你已经具备Es的IK分词器能力) 安装: elasticsearch-plugin install ingest-att ...

  2. Elasticsearch+elasticsearch-head的安装+Kibana环境搭建+ik分词器安装

    一.安装JDK1.8 二.安装ES 三个节点:master.slave01.slave02 1.这里下载的是elasticsearch-6.3.1.rpm版本包 https://www.elastic ...

  3. 全文检索引擎ElasticSearch:文档管理、集成IK分词器

    ElasticSearch 文档管理 添加文档 修改文档 删除文档 文档的查询 IK分词器安装 使用IK分词器 文档管理 添加文档 定位到资源 url http://localhost:9200/{i ...

  4. Elasticsearch 7.8.1 创建索引,IK分词器的使用

    前置知识来自:图解Elasticsearch中的_source._all.store和index属性_1.02^365=1377.41 (Lucene.ES.ELK开发交流群: 370734940, ...

  5. Elasticsearch实现不同索引使用不同的ik分词器词典

    需求说明 原本在IK中,所有索引共用一个词典,热更新词库也是对所有的索引有效. 本文实现,不同的索引,可以配置不同的词典数据 词典数据来自于接口,可以是文件,可以是关系型数据库mysql等 提供数据词 ...

  6. 04.ElasticSearch之IK分词器的安装与使用

    ElasticSearch之IK分词器的安装与使用 前言 安装 离线安装 在线安装 ik分词器测试 扩展(停用)词(典) 测试数据 概念 配置词典 1.修改配置文件 2.新建词典 3.自定义内容 4. ...

  7. 服务器安装配置elasticsearch,kibana,IK分词器和拼音分词器,集群搭建教程

    docker安装配置elasticsearch,kibana和IK分词器 elasticsearch文章系列 前置安装docker 创建docker网络 安装Elasticsearch 运行elast ...

  8. ElasticSerach6.0.1测试拼音分词器,IK分词器,并且次测试语法

    第一步:安装ElasticSearch 6.0.1 下载ElasticSerach,下载IK分词器 由于IK和ElasticSerach已经是编译好的,不需要编译,直接在安装解压修改配置文件即可 详情 ...

  9. ik分词器安装_Elasticsearch-analysis-ik-7.4.0_Linux_安装

    ik分词器安装_Elasticsearch-analysis-ik-7.4.0 文章目录 ik分词器安装_Elasticsearch-analysis-ik-7.4.0 IK分词器安装 1.环境准备 ...

最新文章

  1. 输出程序运行的时间(精确到微秒)
  2. Ubuntu terminal路径太深,名字太长
  3. Python爬虫之旅_高性能异步爬虫
  4. Request登录案例
  5. 火狐 url 乱码_在Firefox中查看URL作为工具提示
  6. 表单提交报错405的解决方式
  7. 自定义字符串函数:strlen,strcat,strcpy,strcmp
  8. uni app map 地图 漂浮问题及方案
  9. 第四次作业----刘滔
  10. java智能提示_【Java】智能提示的设置
  11. linux系统管理命令使用,Linux系统管理命令使用说明
  12. Allegro 使用技巧
  13. HTML5大数据可视化效果(二)可交互地铁线路图
  14. Android Patcher应用增量更新(App补丁式更新,无需下载整个apk)
  15. IAR,STVD和STVP的使用
  16. 对接京东联盟,签名无效
  17. Zigbee之旅:第一个CC2430程序LED-IAR相关设置
  18. 代码动态改变view的大小
  19. html语言乘法口诀表,0044 使用JavaScript在网页上生成九九乘法口诀表
  20. 第10章 项目干系人管理

热门文章

  1. Zero-shot Cross-lingual Transfer of Prompt-based Tuning with a Unified Multilingual Prompt
  2. Amazon丨『云+端』的全球领先者,为何不提是人工智能公司?
  3. “以电折水、水电共计”智能仪表助力农业灌溉走上新模式
  4. PADS的layout单个元器件删除时提示“复用元素无法修改,首先打散复用模块”
  5. 关于西数黑盘那些事 原来这样滴 小伙伴们都惊呆了
  6. SQL -- 游标(详细)
  7. 初,中高级宏观经济学区别和联系
  8. UPC豁免流程精讲!你与大卖的距离,就在这里!
  9. 数仓学习笔记(5)——数仓搭建(DWD层)
  10. 【Thymeleaf】Thymeleaf中的判断语句