elasticsearch开启慢查询
环境:
OS:Centos 7
ES:6.8.5
1.查看索引的设置
curl -u elastic:123456 -XGET "http://192.168.1.69:19200/hospital_info_demo3/_settings?pretty"
2.搜索部分
设置query和fetch慢查询
curl -u elastic:123456 -XPUT "http://192.168.1.69:19200/hospital_info_demo3/_settings" -H 'Content-Type: application/json' -d'
{
"index.search.slowlog.threshold.query.warn": "10s",
"index.search.slowlog.threshold.query.info": "5s",
"index.search.slowlog.threshold.query.debug": "2s",
"index.search.slowlog.threshold.query.trace": "500ms",
"index.search.slowlog.threshold.fetch.warn": "1s",
"index.search.slowlog.threshold.fetch.info": "800ms",
"index.search.slowlog.threshold.fetch.debug": "500ms",
"index.search.slowlog.threshold.fetch.trace": "200ms",
"index.search.slowlog.level": "info"
}'
3.索引部分
设置索引级别的慢查询
curl -u elastic:123456 -XPUT "http://192.168.1.69:19200/hospital_info_demo3/_settings" -H 'Content-Type: application/json' -d'
{
"index.indexing.slowlog.threshold.index.warn": "10s",
"index.indexing.slowlog.threshold.index.info": "5s",
"index.indexing.slowlog.threshold.index.debug": "2s",
"index.indexing.slowlog.threshold.index.trace": "500ms",
"index.indexing.slowlog.level": "info",
"index.indexing.slowlog.source": "1000"
}'
4.查看是否生效
[root@hxl-biz-b42060e-test ~]# curl -u elastic:123456 -XGET "http://192.168.1.69:19200/hospital_info_demo3/_settings?pretty"
{
"hospital_info_demo3" : {
"settings" : {
"index" : {
"search" : {
"slowlog" : {
"level" : "info",
"threshold" : {
"fetch" : {
"warn" : "1s",
"trace" : "200ms",
"debug" : "500ms",
"info" : "800ms"
},
"query" : {
"warn" : "10s",
"trace" : "500ms",
"debug" : "2s",
"info" : "5s"
}
}
}
},
"indexing" : {
"slowlog" : {
"level" : "info",
"threshold" : {
"index" : {
"warn" : "10s",
"trace" : "500ms",
"debug" : "2s",
"info" : "5s"
}
},
"source" : "1000"
}
},
"number_of_shards" : "5",
"provided_name" : "hospital_info_demo3",
"creation_date" : "1670471943496",
"number_of_replicas" : "1",
"uuid" : "ZzeWlProTWqi_uX7ZWfeXw",
"version" : {
"created" : "6080599"
}
}
}
}
}
5.获取日志输出目录
curl -u elastic:123456 -XGET "http://192.168.1.69:19200/_nodes/settings?pretty=true"
在settings.path.logs下找到打印日志的目录。默认情况,慢日志文件名格式为:
<cluster_name>_index_search_slowlog.log
<cluster_name>_index_indexing_slowlog.log
[root@hxl-biz-b42060e-test ~]# curl -u elastic:123456 -XGET "http://192.168.1.69:19200/_nodes/settings?pretty=true"
{
"_nodes" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"cluster_name" : "elasticsearch",
"nodes" : {
"oAfpzKK6R8ScH7FaTw2DxA" : {
"name" : "oAfpzKK",
"transport_address" : "192.168.1.69:9300",
"host" : "192.168.1.69",
"ip" : "192.168.1.69",
"version" : "6.8.5",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "78990e9",
"roles" : [
"master",
"data",
"ingest"
],
"attributes" : {
"ml.machine_memory" : "16657059840",
"xpack.installed" : "true",
"ml.max_open_jobs" : "20",
"ml.enabled" : "true"
},
"settings" : {
"cluster" : {
"name" : "elasticsearch"
},
"node" : {
"attr" : {
"xpack" : {
"installed" : "true"
},
"ml" : {
"machine_memory" : "16657059840",
"max_open_jobs" : "20",
"enabled" : "true"
}
},
"name" : "oAfpzKK"
},
"path" : {
"data" : [
"/home/middle/elasticsearch/data"
],
"logs" : "/home/middle/elasticsearch/logs",
"home" : "/usr/local/services/elasticsearch"
},
"client" : {
"type" : "node"
},
"http" : {
"type" : "security4",
"port" : "19200",
"type.default" : "netty4"
},
"transport" : {
"type" : "security4",
"features" : {
"x-pack" : "true"
},
"type.default" : "netty4"
},
"network" : {
"host" : "192.168.1.69"
}
}
}
}
}
日志目录会出现如下2个文件
-rw-rw-r-- 1 hxl hxl 0 Apr 29 2021 elasticsearch_index_indexing_slowlog.log
-rw-rw-r-- 1 hxl hxl 0 Apr 29 2021 elasticsearch_index_search_slowlog.log