stack-es-标准篇-ElasticsearchClient-combined_fields
世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。
-侯氏工坊
文章目录
- 功能
- 关键字
- 原语句
- java实现
- 所需jar包
功能
- 合并域查询
- 以词项为中心
- 使用同一个分析器
- 跨域查询
- 通过^配置权重
- 相似度算法BM25
关键字
- combined_fields
- query
- fields
- operator
原语句
DELETE index_combined_fieldsPUT index_combined_fields
{"mappings": {"properties": {"title": {"type": "text"},"content": {"type": "text"},"describe": {"type": "text"}}}
}GET index_combined_fields/_mappingPOST index_combined_fields/_doc/1
{"title": "cold porridge","content": "my favorite food is cold porridge","describe": "my favorite cold porridge"
}POST index_combined_fields/_doc/2
{"title": "cold porridge","content": "when it's cold my favorite food is porridge","describe": "my favorite cold porridge"
}POST index_combined_fields/_doc/3
{"title": "hot water","content": "my favorite food is hot water","describe": "my favorite hot water"
}POST index_combined_fields/_doc/4
{"title": "hello good me","content": "my favorite food is hello good me","describe": "my favorite hello good me"
}GET /index_combined_fields/_search
{"_source": [false], "query": {"combined_fields": {"query": "my favorite cold porridge","fields": ["title^2", "content", "describe"],"operator": "and"}},"fields": ["title","content","describe"]
}
java实现
- 实体
@Data
@EsIndex(index = "index_combined_fields")
public class CombinedFieldsEntity {private String title;private String content;private String describe;
}
- 接口
public interface CombinedFieldsService {/*** 域合并查询* @return* @throws Exception*/SearchResponse<Object> combinedFields()throws Exception;
}
- 实现
@Service
public class CombinedFieldsServiceImplimplements CombinedFieldsService {@Resourceprivate ElasticsearchClient elasticsearchClient;@Overridepublic SearchResponse<Object> combinedFields()throws Exception {return elasticsearchClient.search(search -> search.source(CombinedFieldsUtils.sourceConfig()).index(getIndex()).fields(getFields()).query(getCombinedFieldsQuery()),Object.class);}private String getIndex() {return EsAnnotationUtils.getIndex(CombinedFieldsEntity.class);}private List<FieldAndFormat> getFields() {return CombinedFieldsUtils.fields(fieldsStr());}private List<String> fieldsStr() {return EsAnnotationUtils.getFields(CombinedFieldsEntity.class);}private Query getCombinedFieldsQuery() {List<String> dest = Arrays.asList(new String[fieldsStr().size()]);Collections.copy(dest, fieldsStr());dest = dest.stream().map(field -> field.equals("title") ? field = "title^2" : field).collect(Collectors.toList());return CombinedFieldsUtils.combinedFieldsQuery("my favorite cold porridge",dest,CombinedFieldsOperator.And,"title_content_describe_combined_fields");}
}
- 工具
public class CombinedFieldsUtils {public static SourceConfig sourceConfig() {return SourceConfig.of(source -> source.fetch(false));}public static List<FieldAndFormat> fields(List<String> fields) {return fields.stream().map(field -> FieldAndFormat.of(fieldAndFormat -> fieldAndFormat.field(field))).collect(Collectors.toList());}public static Query combinedFieldsQuery(String query,List<String> fields,CombinedFieldsOperator operator,String queryName) {return Query.of(q -> q.combinedFields(combinedFields -> combinedFields.query(query).fields(fields).operator(operator).queryName(queryName)));}
}
所需jar包
- ES注解工具类-002-update
stack-es-标准篇-ElasticsearchClient-combined_fields相关推荐
- WEB前端开发经验总结--WEB标准篇
很久没有写文章,最近一直在忙于找工作和找房子.哎,现在终于安定下来了,哎,又叹息一下,是因为我把去淘宝面试的机会也推掉了,本来以为要卷铺盖回武汉了,哎,不提了,很对不起小马哥,也很对不起自己啊! 现在 ...
- 我所理解的RESTful Web API [Web标准篇]
REST不是一个标准,而是一种软件应用架构风格.基于SOAP的Web服务采用RPC架构,如果说RPC是一种面向操作的架构风格,而REST则是一种面向资源的架构风格.REST是目前业界更为推崇的构建新一 ...
- WCF技术剖析之二十五: 元数据(Metadata)架构体系全景展现[WS标准篇]
元数据实际上是服务终结点的描述,终结点由地址(Address).绑定(Binding)和契约(Contract)经典的ABC三要素组成.认真阅读过<WCF技术剖析(卷1)>的读者相对会对这 ...
- J2SE学习标准篇(转载)
时常看到一些人说掌握了Java,但是让他们用Java做一个实际的项目可能又困难重重,在这里,笔者根据自己的一点理解斗胆提出自己的一些对掌握Java这个说法的标准,当然对于新手,也可以提供一个需要学习哪 ...
- Queue+Stack(C++,标准库中的队列和栈)
STL Queue(先进先出) 头文件#include 成员函数 queue::pop () //出队列 queue::push () //入队列 queue::size () //返回队列中元素个数 ...
- stack - es - 官方文档 - 分页
世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程. -侯氏工坊 文章目录 分页搜索结果 Search after 滚动显示搜索结果 保持搜索上下文活跃 清除滚动 滚 ...
- stack - es - 官方文档 - 内部命中inner_hits
世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程. -侯氏工坊 文章目录 检索内部命中 选项 嵌套内部命中 嵌套的内部命中和_source 嵌套对象字段和内部命中的 ...
- 华为云HCS解决方案笔记HUAWEI CLOUD Stack【面试篇】
目录 HCS方案 一.定义 1.特点 2.优点 二.云服务 1.云管理 2.存储服务 3.网络服务 4.计算服务 5.安全服务 6.灾备服务 7.容器服务 三.应用场景 四.HCS功能层 五.Open ...
- 新标准篇-水土保持方案编制及监测水平评价资质
水平评价实行星级评价,从低到高分为一星级. 二星级.三星级.四星级.五星级. 水平评价工作原则上每年集中开展一次. 中国水土保持学会建立水平评价信息公开共享 平台,提供信息咨询.技术交流以及宣传推介等 ...
- ECMA不同浏览器对es标准的支持
https://www.ecma-international.org/ https://www.ecma-international.org/publications-and-standards/st ...
最新文章
- mysql int(40)_MySQL Integer类型与INT(11)
- 《软件测试的艺术》读书笔记 - 1
- java 枚举类 enum
- Shell 脚本修改 Mac IP地址
- kafka中的groupid
- es6中的promise解读
- 如何在程序中画出实际大小为7CM半径的圆
- Python基础学习1---函数
- linux安装mysql8.0.18_详解mysql8.018在linux上安装与配置过程
- Raki的读paper小记:EDA: Easy Data Augmentation Techniques for Boosting Performance on Text Classification
- jsp 弹出窗口设置大全
- iOS蓝牙开发(一)蓝牙相关基础知识
- 家庭用计算机选购调查报告,【调查报告】计算机选购调查报告.doc
- Android 中定义图片的资源文件
- 登录功能前端+后台php
- mongo数据库创建用户
- 实验一 熟悉常用的Linux操作和Hadoop操作
- 移动端与PC端设计的几项要点
- Y-Combinator
- 华为的鸿蒙河图名字,华为地图起名“河图”,再次震撼国人
热门文章
- 权限管理和备份;规范数据库设计
- All the Windows 10 Technical Preview Editions ISO Direct Download Links !
- 初学者好 |如何从头开始创建一个图像识别的AI应用[ctrl:c+v,你就完成了]
- 节日网页HTML代码 学生网页课程设计期末作业下载 清明节大学生网页设计制作成品下载 DW节日网页作业代码下载
- VS编译错误:mt.exe : general error c101008d: Failed to write the updated manifest to the resource of file
- Java_String_Arrays_Character_BigDecimal_Calendar_Math_System
- svn绿色符号消失的解决办法
- IOS 蓝牙相关-BabyBluetooth蓝牙库介绍(4)
- 夫妻卖盲盒、年入16亿,揭秘泡泡玛特的暴利生意
- iOS Workspace内多project开发