相关语法
官网文档
https://www.elastic.co/guide/cn/elasticsearch/guide/current/index.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html
按时间查找
{
"query": {
"bool": {
"filter": [
{
"range": {
"update_time": {
"gte": "2021-04-06 21:18:25"
}
}
}
]
}
}
}
按关键词+范围搜索
{
"query": {
"bool": {
"must_not": {
"match": {
"online_count": 0
}
},
"filter": [
{
"range": {
"update_time.keyword": {
"gte": "2021-04-14 12:00:00"
}
}
}
]
}
}
}
多条件+范围搜索
{
"query": {
"bool": {
"must": [
{
"term": {
"online_status": 1
}
},
{
"exists": {
"field": "access_time"
}
}
],
"filter": [
{
"range": {
"update_time": {
"gte": "now+8h-23m"
}
}
}
]
}
},
"size": 260
}
查询数量查询
{
"query": {
"match_all": {}
},
"size": 10
}
精确查找
{
"query": {
"term": {
"userName": "jack"
}
},
"size": 10
}
聚合查询
{
"size": 0,
"aggs": {
"indexs": {
"terms": {
"field": "index_code.keyword",
"order": {
"maxValue": "asc"
},
"size": 3
},
"aggs": {
"maxValue": {
"sum": {
"field": "online_count"
}
}
}
}
}
}
模糊查询
{
"query": {
"bool": {
"filter": {
"term": {
"hazard_code.keyword": "141110089005"
}
},
"should": [
{
"wildcard": {
"target_name.keyword": "*合成塔塔壁上部*"
}
},
{
"wildcard": {
"quota_id.keyword": "*41110089005P0002WD01*"
}
},
{
"wildcard": {
"equip_name.keyword": "*10万吨合成氨氨合成塔*"
}
},
{
"wildcard": {
"equip_code.keyword": "*41110089005P000"
}
}
]
}
}
}
错误定位
ignore_malformed 错误数据无法匹配问题
https://www.coder.work/article/7401749
出发ignore_malformed后, 该错误字段不会索引, 故可以使用exists匹配该字段,从而达到搜索的目的