zoukankan      html  css  js  c++  java
  • 51.多条件组合查询

    主要知识点:

    • 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

    }

    }

    }

    }

    }

    }

  • 相关阅读:
    ubuntu输入法安装
    ffmpeg使用
    sourceforge无法登陆?没关系~~
    六大代码问题检验你的JAVA知识(转)
    关于Struts处理异常框架的小例子
    Spring Security连接数据库查询实例
    关于Struts的Token
    JAVA md5、SHA加密类
    利用commons upload+ffmpeg+mencoder完成视频的上传与转换
    初始化SSD1963
  • 原文地址:https://www.cnblogs.com/liuqianli/p/8471681.html
Copyright © 2011-2022 走看看