文章目录
- 1. Query Context & Filter Context
- 2. 条件组合
- 3. bool 查询
- 4. bool 查询语句
- 5. 如何解决结构化查询 -“包含而不是相等” 的问题
- 6 Filter Context - 不影响算分
- 7. Query Context - 影响算分
- 8. bool 嵌套
- 9. 查询语句的结构,会对相关度算分产生影响
- 10. 控制字段的 Boosting
- 11. Not Quite Not
- 12 Boosting Query
- 13 知识点回顾
1. Query Context & Filter Context
高级搜索的功能,支持多想文本输入,针对多个字段进行搜索
搜索引擎一般也提供时间,价格等条件过滤
在 ES 中,有 Query 和 Filter 两种 Context
- Query Context :相关性算分
- Filter Context :不需要算分(YES OR NO), 可以利用 Cache 获得更好的性能
2. 条件组合
假设搜索一本电影
- 评论中包含了 Guitar ,用户打分高于 3 分,同时上映时间在 1993 到 2000 年之间
这个搜索包含了 3 段逻辑,针对不同的字段
- 评论字段中要包含 Guitar 、用户评论大于 3、上映时间日期在给定范围内
同时包含这三个逻辑,并且有比较好的性能
- 复合查询: bool Query
3. bool 查询
一个 bool 查询,是一个或者多个查询子句的组合
总共包含 4 种子句,其中 2 种会影响算分,2 种不影响算分
相关性并不只是全文本搜索的专利。也适合 yes | no 的子句,匹配的子句越多,相关性评分越高。如果多条查询子句被合并为一条复合查询语句,比如 bool 查询,则每个查询子句计算得出的评分会被合并到总的相关性评分中。
4. bool 查询语句
- 子查询可以任意顺序出现
- 可以嵌套多个查询
- 如果你的 bool 查询中,没有 must 条件,should 中必须满足一条查询
5. 如何解决结构化查询 -“包含而不是相等” 的问题
5.1 增加 count 字段,使用 bool 查询
从业务角度,按需改进数据模型
6 Filter Context - 不影响算分
7. Query Context - 影响算分
8. bool 嵌套
9. 查询语句的结构,会对相关度算分产生影响
同一层级下的竞争字段,具有相同的权重
通过嵌套 bool 查询,可以改变对算分的影响
10. 控制字段的 Boosting
11. Not Quite Not
12 Boosting Query
13 知识点回顾
- Query Context vs Filter Context
- Bool Query - 更多的条件组合
- 查询结构与相关性算分
- 如何控制查询的精确度
- Boosting & Boosting Query
参考资料:
极客时间:Elasticsearch核心技术与实战