ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

elasticsearch常用命令

elasticsearch常用命令

最近接触到elasticsearch,需要使用命令进行多种操作,由于对es不是很熟悉,记录一下常用的curl和kinaba命令。

1.查询es信息

curl

curl -XGET "http://192.168.10.101:9200/" -H "kbn-xsrf: reporting"

kibana

GET /

2.查询所有索引信息

curl

curl -XGET "http://192.168.10.101:9200/_cat/indices?v" -H "kbn-xsrf: reporting"

kibana

GET /_cat/indices?v

3.查询节点状态

curl

curl -XGET "http://192.168.10.101:9200/_cat/nodes?v" -H "kbn-xsrf: reporting"

kibana

GET /_cat/nodes?v

4.查询索引结构信息

curl

curl -XGET "http://192.168.10.101:9200/proof_data?pretty=true" -H "kbn-xsrf: reporting"

kibana

GET /proof_data?pretty=true

5.创建索引

curl

curl -XPUT "http://192.168.10.101:9200/new_index_data/" -H "kbn-xsrf: reporting" -H "Content-Type: application/json" -d'
{"aliases" : { },"mappings" : {"properties" : {"BIZ_ID" : {"type" : "text","fields" : {"keyword" : {"type" : "keyword","ignore_above" : 256}}},"BIZ_TYPE_ID" : {"type" : "text","fields" : {"keyword" : {"type" : "keyword","ignore_above" : 256}}},"CHANNEL" : {"type" : "text","fields" : {"keyword" : {"type" : "keyword","ignore_above" : 256}}},"CREATE_TIME" : {"type" : "date"},"ORGANIZE_CODE" : {"type" : "text","fields" : {"keyword" : {"type" : "keyword","ignore_above" : 256}}},"TRANSACTION_ID" : {"type" : "text","fields" : {"keyword" : {"type" : "keyword","ignore_above" : 256}}},"USER_ID" : {"type" : "text","fields" : {"keyword" : {"type" : "keyword","ignore_above" : 256}}},"USE_ENCRYPT" : {"type" : "text","fields" : {"keyword" : {"type" : "keyword","ignore_above" : 256}}},"id" : {"type" : "long"},"virtual_channel_id" : {"type" : "text","fields" : {"keyword" : {"type" : "keyword","ignore_above" : 256}}}}}
}'

kibana

PUT /new_index_data/
{"aliases" : { },"mappings" : {"properties" : {"BIZ_ID" : {"type" : "text","fields" : {"keyword" : {"type" : "keyword","ignore_above" : 256}}},"BIZ_TYPE_ID" : {"type" : "text","fields" : {"keyword" : {"type" : "keyword","ignore_above" : 256}}},"CHANNEL" : {"type" : "text","fields" : {"keyword" : {"type" : "keyword","ignore_above" : 256}}},"CREATE_TIME" : {"type" : "date"},"ORGANIZE_CODE" : {"type" : "text","fields" : {"keyword" : {"type" : "keyword","ignore_above" : 256}}},"TRANSACTION_ID" : {"type" : "text","fields" : {"keyword" : {"type" : "keyword","ignore_above" : 256}}},"USER_ID" : {"type" : "text","fields" : {"keyword" : {"type" : "keyword","ignore_above" : 256}}},"USE_ENCRYPT" : {"type" : "text","fields" : {"keyword" : {"type" : "keyword","ignore_above" : 256}}},"id" : {"type" : "long"},"virtual_channel_id" : {"type" : "text","fields" : {"keyword" : {"type" : "keyword","ignore_above" : 256}}}}}}

6.查询索引的Settings配置

curl

curl -XGET "http://192.168.10.101:9200/new_index_data/_settings" -H "kbn-xsrf: reporting"

kibana

GET /new_index_data/_settings

7.查询索引下所有数据

curl

# 带条件查询
curl -XGET "http://192.168.10.101:9200/proof_data/_search" -H "kbn-xsrf: reporting" -H "Content-Type: application/json" -d'
{"query": {"match_all": {}}
}'# 不带条件查询
curl -XGET "http://192.168.10.101:9200/proof_data/_search" -H "kbn-xsrf: reporting"

kibana

GET /proof_data/_search
{"query": {"match_all": {}}}

8.查询索引下数据总量

curl

curl -XGET "http://192.168.10.101:9200/proof_data/_count" -H "kbn-xsrf: reporting"

kibana

GET /proof_data/_count

9.删除索引

curl

curl -XDELETE "http://192.168.10.101:9200/new_index_data/" -H "kbn-xsrf: reporting"

kibana

DELETE /new_index_data/

10.删除索引下的数据

curl

curl -XPOST "http://192.168.10.101:9200/index_name/_delete_by_query" -H "kbn-xsrf: reporting" -H "Content-Type: application/json" -d'
{"query":{"match_all":{}}
}'

此语句可以根据query条件,进行选择性删除数据。

kibana

POST /index_name/_delete_by_query
{"query":{"match_all":{}}
}

11.查询es健康状况

curl

curl -XGET "http://192.168.10.101:9200/_cat/health?v" -H "kbn-xsrf: reporting"

kibana

GET /_cat/health?v

返回列表