https://www.elastic.co/cn/what-is/elasticsearch-sql
确认版本号:GET http://host:9200
一种是直接用sql搜索并返回结果,另一种返回的是ES转换语句。版本:7.14
https://www.elastic.co/guide/en/elasticsearch/reference/7.14/sql-translate.html
https://www.elastic.co/guide/en/elasticsearch/reference/7.14/sql-rest-format.html
版本:6.5
https://www.elastic.co/guide/en/elasticsearch/reference/6.5/sql-rest.html
https://www.elastic.co/guide/en/elasticsearch/reference/6.5/sql-translate.html
如果您真的要写,或者想小改动
如果搜索不出来,可以试试field去掉keyword,或者添加上keyword
POSTMAN内支持注释
{
//聚合数据
"aggs": {
"first": {
"terms": {
"field": "bizname.keyword",
"size": 10
},
"aggs": {
"second": {
"terms": {
"field": "eventstatus.keyword",
"order": {
"_count": "asc"
}
}
}
}
}
},
"query": {
// "match_all":{}
//match query 知道分词器的存在,会对field进行分词操作,然后再查询
"bool": {
"must": {
"terms": {
"bizName": [
"hfish"
// "xxxxx"
]
}
}
// 建议直接用filter,精准匹配,返回的文档必须满足filter子句的条件。特点:对结果进行缓且避免计算分值
// "filter": [
// {
// "bool": {
// "must": [
// // {
// // "match_phrase": {
// // "bizName": {
// // "query": "xxxxx"
// // }
// // }
// // },
// {
// "match_phrase": {
// "eventstatus": {
// "query": "RESOLVED"
// }
// }
// }
// ]
// }
// },
// {
// "range": {
// "createTime": {
// // "lte": "1635756595000", //如果是时间戳,需要自行计算。
// // "gte": "now",
// // "format": "yyyy-MM-dd"
// }
// }
// }
// ]
}
},
"sort": {
// "id":"desc" 排序,key为列
},
"size": 1, //返回大小
// "from":1, //用于分页,结合size
"_source": {
"include": [
// "logModel"//只返回固定内容
// "logModel.log" // 支持取二级内容
],
"exclude": [
// "logModel","permissions" //排除某些字段
]
}
}
Elasticsearch 版本 7.12.0
添加multi_termsaggs #67597(问题:#65623)
https://www.elastic.co/guide/en/elasticsearch/reference/current/release-notes-7.12.0.html
聚合语法aggs,包括结果看起来就好很多。
{
"aggs": {
"attack_ip": {
"multi_terms": {
"terms": [
{
"field": "attack_ip.keyword"
},
{
"field": "geo.keyword"
},
{
"field": "type.keyword"
},
{
"field": "severity_label.keyword"
}
],
"size": 3
}
}
},
"size": 0
}
参考链接:
https://blog.csdn.net/qq_39985298/article/details/118488285



