ES 学习笔记 (二. 查询的传参)

1.单个匹配查询 match query 

{
   "query": {
     "match": {
        "merchant_name":"健康"
     }
   }
}

2.查询所有 match_all

{"query":{"match_all":{"title":"标题一样"}}}

3.精确查询

{
    "query":{
        "term":{
            "assistant_id": 200186
        }
    }
}

4.排序

{
    "query":{
        "term":{
            "assistant_id": 200186
        }
    },
    "sort":{
        "_score":"asc"
    }
}

5. 分页

{
    "query":{
        "term":{
            "assistant_id": 200186
        }
    },
    "from": 1, // 从几条数据开始
    "size": 5 // 页数
}

6. 范围查询

{
    "query":{
       "range" : {
           "x_created_at": {
               "gte": "2021-09-07", // 大于等于
               "lte": "2021-09-08" // 小于等于
           }
       }
    }
}

7. 精确多个值查询 相当于in

{
    "query":{
        "terms":{
            "assistant_id": [200186,200621]
        }
    }
}

8. bool 组合查询

must 相当于 and 

must_not 相当于 !=

should 相当于or

// must 用法示例
{
  "query": {
    "bool": {
      "must": [
        // assistant_id = 200186 and merchat_name like "%你好%"
        {"term": {"assistant_id":200186}}, 
        {"match":{"merchant_name": "你好"}}
      ]
    }
  }
}
// should 用法示例
{
  "query": {
    "bool": {
      "should": [
        // assistant = 200186 or merchant_name like "%hello%"
        {"term": {"assistant_id":200186}},
        {"match":{"merchant_name": "hello"}}
      ]
    }
  }
}
// must_not 示例
{
  "query": {
    "bool": {
       // channel != 1
      "must_not": [
        {"term": {"channel":1}}
      ]
    }
  }
}
//  组合范围排序
{
  "query": {
    "bool": {
      "must": [
        {"term": {"channel":1}},
        { "range":{
          "x_created_at":{
              "gte":"2021-09-06"
          }
      }}
      ]
    }
  },
  "sort": {
      "_score":"asc"
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值