【Elasticsearch】 Compound Queries

Elasticsearch Compound Queries

Elasticsearch 的 Compound Queries 是一种强大的工具,用于组合多个查询子句,以实现更复杂的搜索逻辑。这些查询子句可以是叶查询(Leaf Queries)或复合查询(Compound Queries),并且可以用于组合结果和分数、改变行为或从查询上下文切换到过滤上下文。

主要的复合查询类型

  1. bool 查询

    • 用于组合多个叶查询或复合查询子句,支持 mustshouldmust_notfilter 子句。mustshould 子句的分数会被合并,而 must_notfilter 子句在过滤上下文中执行。

    JSON复制

    GET /products/_search
    {
      "query": {
        "bool": {
          "must": [
            { "match": { "description": "wireless headphones" } }
          ],
          "filter": [
            { "term": { "brand": "BrandA" } }
          ],
          "should": [
            { "range": { "price": { "lte": 100 } } }
          ],
          "must_not": [
            { "term": { "color": "red" } }
          ]
        }
      }
    }
  2. boosting 查询

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值