首页 > 其他 > 详细

51.多条件组合查询

时间:2018-02-26 10:39:48      阅读:227      评论:0      收藏:0      [点我收藏+]

主要知识点:

  • bool组合查询
  • bool和filter组合查询
  • bool,filter嵌套查询
  • 直接用filter查询,并以_score排序

   

   

一、bool组合查询

GET /website/article/_search

{

"query": {

"bool": {

"must": [

{

"match": {

"title": "elasticsearch"

}

}

],

"should": [

{

"match": {

"content": "elasticsearch"

}

}

],

"must_not": [

{

"match": {

"author_id": 111

}

}

]

}

}

}

二、boolfilter组合查询

{

"bool": {

"must": { "match": { "title": "how to make millions" }},

"must_not": { "match": { "tag": "spam" }},

"should": [

{ "match": { "tag": "starred" }}

],

"filter": {

"range": { "date": { "gte": "2014-01-01" }}

}

}

}

   

boolmustmust_notshouldfilter

   

每个子查询都会计算一个document针对它的相关度分数,然后bool综合所有分数,合并为一个分数,filter是不会计算分数

   

三、bool,filter嵌套查询

{

"bool": {

"must": { "match": { "title": "how to make millions" }},

"must_not": { "match": { "tag": "spam" }},

"should": [

{ "match": { "tag": "starred" }}

],

"filter": {

"bool": {

"must": [

{ "range": { "date": { "gte": "2014-01-01" }}},

{ "range": { "price": { "lte": 29.99 }}}

],

"must_not": [

{ "term": { "category": "ebooks" }}

]

}

}

}

}

四、直接用filter查询,并以_score排序

GET /company/employee/_search

{

"query": {

"constant_score": {

"filter": {

"range": {

"age": {

"gte": 30

}

}

}

}

}

}

51.多条件组合查询

原文:https://www.cnblogs.com/liuqianli/p/8471681.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!