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

    }

    }

    }

    }

    }

    }

  • 相关阅读:
    数值分析实验之数值积分法(java 代码)
    Python 数据处理
    Python 网络爬虫
    数据库系统开发——旅游公司机票查询及预订系统
    Python词云生成
    Python库的安装与查看
    Python词频统计
    Python程序设计训练
    Python编程基础训练
    如何在同一Linux服务器上创建多站点
  • 原文地址:https://www.cnblogs.com/liuqianli/p/8471681.html
Copyright © 2011-2022 走看看