码迷,mamicode.com
首页 > 其他好文 > 详细

51.多条件组合查询

时间:2018-02-26 11:17:28      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:content   分数   red   arch   ons   col   bsp   size   body   

主要知识点:

  • 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.多条件组合查询

标签:content   分数   red   arch   ons   col   bsp   size   body   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!