ES 常用查询语句

发布时间 2023-08-11 11:22:13作者: 章怀柔

配置查询

_cluster/settings
_cluster/settings?flat_settings
_cluster/settings?include_defaults
_cluster/settings?include_defaults&flat_settings
/_stats/fielddata
/_stats/fielddata?fields=*
/_nodes/stats/indices/fielddata?fields=*
/_nodes/stats/indices/fielddata?level=indices&fields=*

indices.breaker.fielddata.limit fielddata级别限制,默认为堆的60%
indices.breaker.request.limit request级别请求限制,默认为堆的40%
indices.breaker.total.limit 保证上面两者组合起来的限制,默认堆的70%
indices.fielddata.cache.size

索引查询

指定显示哪些列
GET /_cat/indices/twitter?pri&v&h=health,index,pri,rep,docs.count,mt
每一个索引使用了多少内存
GET /_cat/indices?v&h=i,tm&s=tm:desc
哪些索引状态是yellow
GET /_cat/indices?v&health=yellow
哪个索引文件最多
GET /_cat/indices?v&s=docs.count:desc
每个节点的分片数和磁盘使用情况
GET /_cat/allocation?v
fielddata 显示每个节点字段所占的堆空间
GET /_cat/fielddata?v
GET /_cat/fielddata?v&fields=name,addr
recovery 显示索引恢复情况
GET /_cat/recovery?v
thread_pool 显示每个节点线程运行情况。
GET /_cat/thread_pool?v
GET /_cat/thread_pool/bulk?v
GET /_cat/thread_pool/bulk?v&h=id,name,active,rejected,completed
shards 显示每个索引各个分片的情况
GET /_cat/shards?v
GET /_cat/shards/myindex?v
GET _cat/shards?h=index,shard,prirep,state,unassigned.reason
segments 显示每个segment的情况
GET /_cat/segments?v
GET /_cat/segments/myindex?v

优化设置

gateway.recover_after_data_nodes: 3
gateway.recover_after_time: 5m
gateway.expected_data_nodes: 3

system.service

 cat /usr/lib/systemd/system/es.service
[Unit]
Description=Elasticsearch
Documentation=http://www.elastic.co
Wants=network-online.target
After=network-online.target
[Service]
User=es
Group=es
ExecStart=/usr/local/elasticsearch-7.8.1/bin/elasticsearch
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=2s
StandardOutput=journal
StandardError=inherit
# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65536
# Specifies the maximum number of processes
LimitNPROC=4096

# Specifies the maximum number of bytes of memory that may be locked into RAM
# Set to "infinity" if you use the 'bootstrap.memory_lock: true' option
# in elasticsearch.yml and 'MAX_LOCKED_MEMORY=unlimited' in /etc/sysconfig/elasticsearch
#LimitMEMLOCK=infinity
LimitMEMLOCK=infinity
# Disable timeout logic and wait until process is stopped
TimeoutStopSec=0
# SIGTERM signal is used to stop the Java process
KillSignal=SIGTERM
# Java process is never killed
SendSIGKILL=no
# When a JVM receives a SIGTERM signal it exits with code 143
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable --now es