网站首页 > 博客文章 正文
ES - Query DSL (Domain Specific Language)
ES提供了一套基于JSON完整的DSL(特定域语言)来定义查询。由 `叶子查询子句` 及 `复合查询子句` 两种类型子句组成抽象树查询(AST)。
概念相关
- 相关性得分 - Relevance Scores
默认情况下,ES按照相关性得分对匹配的结果进行排序,来衡量每个文档与查询的匹配度. 在 `search api` 的元数据`_score`进行返回
- 查询上下文 - Query Context
主要关注文档与查询子句的匹配程度如何
- 过滤器上下文 - Filter Context
过滤上下文只返回是否匹配到相应文档
GET /_search
{
"query": {
"bool": {
"must": [
{ "match": { "title": "Search" }},
{ "match": { "content": "Elasticsearch" }}
],
"filter": [
{ "term": { "status": "published" }},
{ "range": { "publish_date": { "gte": "2015-01-01" }}}
]
}
}
}
复合查询 - Compound Query
复合查询包装了其它复查询以及叶子查询,以组合其结果和分数,更改其行为或者从查询切换到过滤上下文。有`bool query` `boosting query` `contant_socre query` `dis_max query` `function_score query `
* [bool query](https://www.elastic.co/guide/en/elasticsearch/reference/7.x/query-dsl-bool-query.html#bool-min-should-match)
查询类型
- must 子句(查询)必须出现在匹配的文档中,并将有助于得分
- filter 必须出现在匹配的文档中。filter子句在过滤上下文中执行,_score会被忽略,并且子句会被缓存
- should 子句应该出现在匹配中。注意与`minimum_should_match`参数使用
- must_not 不必在匹配中出现。
示例如下:
POST _search
{
"query": {
"bool" : {
"must" : {
"term" : { "user.id" : "kimchy" }
},
"filter": {
"term" : { "tags" : "production" }
},
"must_not" : {
"range" : {
"age" : { "gte" : 10, "lte" : 20 }
}
},
"should" : [
{ "term" : { "tags" : "env1" } },
{ "term" : { "tags" : "deployed" } }
],
"minimum_should_match" : 1,
"boost" : 1.0
}
}
}
- minimum_should_match
使用minimum_should_match参数指定返回的文档必须匹配的应当子句的数量或百分比。
Term-Level Query
根据结构化数据中的精确值进行查询
* exists - 检查文档中字段是否存在
* fuzzy - 模糊匹配
* ids query - 按照文档id查询
GET /_search
{
"query": {
"ids" : {
"values" : ["1", "4", "100"]
}
}
}
* prefix query - 返回在提供的字段中包含特定前缀的文档
* range query - 区间查询
区间查询时有 `lt`, `lte` , `gt`, `gte`, `format`, relation, `time_zone`, `boost` 等参数
GET /_search
{
"query": {
"range": {
"timestamp": {
"gte": "now-1d/d",
"lt": "now/d"
}
}
}
* regexp query - 正则匹配查询
* term query - 精确值查询
* terms query - 多值查询
* terms_set query - 返回提供的字段中包含最少数目的精确文档
* type query
* wildcard query
term 查询时有些较长的字符串不一定能够匹配得上,可以用 [match_phase](https://www.elastic.co/guide/en/elasticsearch/reference/7.x/query-dsl-match-query-phrase.html) - 查询将分析文本,并从分析的文本中创建短语查询
猜你喜欢
- 2024-10-24 持久层框架JPA与Mybatis该如何选型
- 2024-10-24 hibatis--mybatis,自动生成SQL, 通用Mapper, 通用Dao
- 2024-10-24 Elasticsearch 6.0.0官方参考指南翻译
- 2024-10-24 推荐一个高效美观易用的服务器运维工具
- 2024-10-24 Java 操作之RestHighLevelClient查询详解
- 2024-10-24 如何在 Elasticsearch 上应用机器学习排序插件
- 2024-10-24 「开源资讯」Apache Solr 8.6.0 发布,Java 全文搜索服务器
- 2024-10-24 最轻量级的Kubernetes云原生日志框架Loki
- 2024-10-24 ElasticSearch学习系列 - (3) Python操作es
- 2024-10-24 全功能orm工具sorms 1.0.10 发布,合使用Spring,Spring boot用户
你 发表评论:
欢迎- 05-30springboot 集成redisson 以及分布式锁的使用
- 05-30去哪儿技术面:10亿数据如何最快速插入MySQL?
- 05-30redis介绍
- 05-30redission YYDS
- 05-30手把手教你springboot集成mybatis
- 05-30mybatis根据表逆向自动化生成代码:自动生成实体类、mapper文件
- 05-30越来越大的微信小程序
- 05-30SpringBoot之数据访问——访问SQL数据库!
- 422℃用AI Agent治理微服务的复杂性问题|QCon
- 420℃手把手教程「JavaWeb」优雅的SpringMvc+Mybatis整合之路
- 401℃初次使用IntelliJ IDEA新建Maven项目
- 399℃Maven技术方案最全手册(mavena)
- 394℃IntelliJ IDEA 2018版本和2022版本创建 Maven 项目对比
- 389℃InfoQ 2024 年趋势报告:架构篇(infoq+2024+年趋势报告:架构篇分析)
- 389℃从头搭建 IntelliJ IDEA 环境(intellij idea建包)
- 384℃IT全明星|IntelliJ IDEA学习笔记(四、idea中怎么创建maven项目)
- 最近发表
- 标签列表
-
- powershellfor (55)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)