说明:本文在ES 5.4.0版本上验证。
Elasticsearch从2.2版本开始提供 Profile API 供用户检查检索、聚合、过滤执行时间和其他细节信息,帮助用户分析每次检索各个环节所用的时间。
官方文档:
Profiling Queries
https://www.elastic.co/guide/en/elasticsearch/reference/5.4/_profiling_queries.html
使用方法
要使用Profile API,需要在查询中加上"profile": true
,具体示例如下:
GET/POST /test/_search
{
"profile": true,
"query": {
"term": {
"message": {
"value": "search"
}
}
},
"aggs": {
"non_global_term": {
"terms": {
"field": "agg"
},
"aggs": {
"second_term": {
"terms": {
"field": "sub_agg"
}
}
}
},
"another_agg": {
"cardinality": {
"field": "aggB"
}
},
"global_agg": {
"global": {
},
"aggs": {
"my_agg2": {
"terms": {
"field": "globalAgg"
}
}
}
}
},
"post_filter"