ES查询例子

es查询例子,记录一下

统计查询

1.查询正则regexp,查询单一值term,时间范围 range,统计aggs, 返回结果集_source

GET index*/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "regexp": {
            "field1": "condition1XX"
          }
        },
        {
          "term": {
            "field2": "condition2XX"
          }
        },
        {
          "range": {
            "field3_time": {
              "gte": "2019-11-19 00:00:00.000",
              "lte": "2019-11-20 00:00:00.000"
            }
          }
        }
      ]
    }
  },
  "size": 0,
  "aggs": {
    "filed1": {
      "terms": {
        "field": "filed4",
        "size": 1000
      },
      "aggs": {
        "rated": {
          "top_hits": {
            "sort": [
              {
                "filed5_order": {
                  "order": "desc"
                }
              }
            ],
            "size": 1
          }
        }
      }
    }
  },
  "_source": [
    "field1",
    "field2",
    "field3",
    "field4",
    "field5",
    "field6"
  ]
}

2.查询多条件值使用terms

GET index2*/_search
 
{
 
  "query": {
 
    "bool": {
 
      "must": [
 
        {
 
          "terms": {
 
            "uri": ["condition1","condition2"]
           }
        }
    }
 }
}

3. 模糊查询多个

{"query": {
    "bool": {
        "must": [
            {"bool": {"should": [{
                    "regexp": {
                        "Response-Content-Type" : "application/csv.*"
                    }
                },{
                    "regexp": {
                        "Response-Content-Type" : "application/csv.*"
                    }
                }]
}
}
}]
}
}

4.  查询不包含

{"query": {
    "bool": {
        "must_not": { "term": {
            "filed1" : "-"
        }
        }
注意补齐

5. 时间范围查询指定时区

{
                "range":{
                    "field": {
                        "gte": start_time,
                        "lte": end_time,
                        "format": "yyyy-MM-dd HH:mm:ss",
                        "time_zone": "+08:00"
                    }
                }
            }

6. 设置超时时间

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值