试试搜索一下吧

es terms聚合个别字段特别慢

Elasticsearch | 作者 famoss | 发布于2018年11月25日 | 阅读数:1869

 {
"request": "POST /api/1 HTTP/1.1",
"referer": "-",
"server_name": "abc.bcd.com",
"status_code": "tengineNormal",
"scheme": "http",
"reqbody": """""""",
"request_method": "POST",
"source": "idc",
"ua": "Go-http-client/1.1",
"type": "tengine.access.log",
"hostname": "163-6.linux.hdfs.com",
"index_time": "08-2018-11-25",
"request_time": "6",
"up_addr": "172.0.0.20:9998",
"host": "abc.bcd.com",
"sent_http_uid": "-",
"content_length": "1837",
"crp": "-",
"st": "2018-11-25 08:24:16",
"sent_http_rid": "-",
"X-Request-Id": "b7910afssh5entveo0eg",
"byte": "2155",
"sent_http_tid": "-",
"ip": "172.29.211.161",
"remote_port": "63537",
"gzip_ratio": "-",
"bytes_sent": "2302",
"request_url": "/api/1",
"forwarded": "-",
"request_uri": "/api/1",
"@timestamp": "1543105456000",
"timeuse": "6",
"csi": "-",
"upstream_response_time": 6,
"bytes_recv": "2102",
"user": " -",
"status": "200",
"server_protocol": "HTTP/1.1"
}
 
类似于将上述文档写入es,对es做分组时,request_url的聚合时间比其余字段都慢了好多倍(类型都是keyword)(如1亿数据量时,比如hostname聚合只需要1s,但是request_url需要4s)。
 
以下是聚合语句。
{
"size": 0,
"profile":true,
"aggs": {
"2": {
"terms": {
"field": "request_url"
}
}
},
"query": {
"bool": {
"filter": [{
"range": {
"@timestamp": {
"gte" : "now-1h",
"lt" : "now"
}
}
}]
}
}
}
es版本 6.2.4
已邀请:

rochy - rochy_he

赞同来自:

可以在字段的 mapping 里面开启 eager_global_ordinals
PUT my_index/_mapping/_doc
{
"properties": {
"request_url": {
"type": "keyword",
"eager_global_ordinals": true
}
}
}

要回复问题请先登录注册