admin管理员组文章数量:1641841
#子条件查询: 子条件查询又分为Query context 和 Filter context
#符合条件查询: 以一定的逻辑组合子条件查询
#子条件查询
Query Context
在查询过程中,除了判断文档是否满足查询条件外,ES还会计算一个_source来表示匹配的程度,旨在判断文档与查询条件的匹配的有多好。返回值有一个Score分数来标识。
常用查询:全文本查寻(文本类型)、字段级别查询(数组、日期…)
全文本查
模糊匹配,会把关键字分开搜索,不会当成一个整体。例如搜索Elastic搜索,会匹配Elastic和搜索两个关键字。
-
{
-
"query":{
-
"match":{
-
"author":"大哥"
-
}
-
}
-
}
短语匹配,把关键字当一个不可分的短语
-
{
-
"query":{
-
"match_phrase":{
-
"title":"Elastic搜索"
-
}
-
}
-
}
多字段匹配,寻找author和title包括关键字的
-
{
-
"query":{
-
"multi_match":{
-
"query":"Elastic搜索",
-
"filter": ["author","title"]
-
}
-
}
-
}
语法查询
-
{
-
"query":{
-
"query_string": {
-
"query":"Elastic搜索 AND 入门"
-
}
-
}
-
}
多条件语法
-
{
-
"query":{
-
"query_string": {
-
"query":"(Elastic搜索 AND 入门) OR Python"
-
}
-
}
-
}
多条件语法多字段查
-
{
-
"query":{
-
"query_string": {
-
"query":"Elastic OR Python",
-
"fields":["title","author"]
-
}
-
}
-
}
按字段查
关键词term
-
{
-
"query":{
-
"term":{
-
"word_count":1000
-
}
-
}
-
}
按范围查,关键词:range
-
{
-
"query":{
-
"range":{
-
"word_count":{
-
"gte":1000, //后面这个e就是equal
-
"lte":2000
-
}
-
}
-
}
-
}
按日期
-
{
-
"query":{
-
"range":{
-
"date":{
-
"gte":"2017-1-1", //后面这个e就是equal
-
"lte":"now"
-
}
-
}
-
}
-
}
Filter Context
关键词:bool,只关心查询是true or false,不关心查询好的程度。
-
{
-
"query": {
-
"bool":{
-
"filter":{
-
"term":{
-
"word_count":1000
-
}
-
}
-
}
-
}
-
}
#符合条件查询
组合上述子条件
固定分数查询
关键词:constant_score
-
{
-
"query":{
-
"constant_score":{ //只支持filter,不支持match
-
"filter":{
-
"match":{
-
"title":"Elastic搜索"
-
}
-
},
-
"boost":2 //指定分数为2
-
}
-
}
-
}
布尔查询
关键词should
-
{
-
"query":{
-
"should":[
-
{
-
"match":{
-
"author":"大哥"
-
}
-
},
-
{
-
"match":{
-
"title":"Elastic搜索"
-
}
-
}
-
]
-
}
-
}
关键词must
-
{
-
"query":{
-
"bool":{
-
"must":[
-
{
-
"match":{
-
"author":"大哥"
-
}
-
},
-
{
-
"match":{
-
"title":"Elastic搜索"
-
}
-
}
-
],
-
"filter":[
-
"term":{
-
"word_count":1000
-
}
-
]
-
}
-
}
-
}
关键词must_not
-
{
-
"query":{
-
"bool":{
-
"must_not":{
-
"term":{
-
"author":"郑联军"
-
}
-
}
-
}
-
}
本文标签: 高级Elasticsearch
版权声明:本文标题:elasticsearch高级查询整理 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1729330281a1196302.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论