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. 设置超时时间