elasticsearch 常用command
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了elasticsearch 常用command相关的知识,希望对你有一定的参考价值。
elasticsearch常用命令检查es版本信息
curl IP:9200
查看集群是否健康
http://IP:9200/_cat/health?v
curl 'IP:9200/_cat/health?v'
查看节点列表
http://IP:9200/_cat/nodes?v
curl 'IP:9200/_cat/nodes?v'
列出所有索引及存储大小
http://IP:9200/_cat/indices?v
curl 'IP:9200/_cat/indices?v'--查询所有索引及数据大小
创建索引
创建索引名为XX,默认会有5个分片,1个索引
curl -XPUT 'IP:9200/XX?pretty'
删除指定索引
curl -XDELETE 'IP:9200/_index?pretty'
添加一个类型
curl -XPUT 'IP:9200/XX/external/2?pretty' -d '
{
"gwyy": "John"
}'
更新一个类型
curl -XPOST 'IP:9200/XX/external/1/_update?pretty' -d '
{
"doc": {"name": "Jaf"}
}'
文档删除-单个: curl -XDELETE 'localhost:9200/XX/external/1?pretty'
删除为1的文档
文档删除-多个:
curl -XDELETE 'localhost:9200/customer/external/_query?pretty' -d '
{
"query": { "match": { "name": "John Doe" } }
}'
注:首先查询出所有name为John Doe的,然后一起删除
文档批处理-创建:创建一个Id为21和22的文档
curl -XPOST 'localhost:9200/customer/external/_bulk?pretty' -d '
{"index":{"_id":"21"}}
{"name": "John Doe" }
{"index":{"_id":"22"}}
{"name": "Jane Doe" } '
[[email protected] ~]# curl -XPOST 'localhost:9200/customer/external/_bulk?pretty' -d '
> {"index":{"_id":"21"}}
> {"name": "John Doe" }
> {"index":{"_id":"22"}}
> {"name": "Jane Doe" }
> '
{
"took" : 35,
"errors" : false,
"items" : [
{
"index" :
{
"_index" : "customer",
"_type" : "external",
"_id" : "21",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"created" : true,
"status" : 201
}
},
{
"index" :
{
"_index" : "customer",
"_type" : "external",
"_id" : "22",
"_version" : 1,
"result" : "created",
"_shards" :
{
"total" : 2,
"successful" : 1,
"failed" : 0
},
"created" : true,
"status" : 201
}
}
]
}
文档批处理:一个更新,一个删除
curl -XPOST 'localhost:9200/customer/external/_bulk?pretty' -d '
{"update":{"_id":"21"}}
{"doc": { "name": "Jimmy" } }
{"delete":{"_id":"22"}}
'
参考https://www.jianshu.com/p/1e9e51454aa5
以上是关于elasticsearch 常用command的主要内容,如果未能解决你的问题,请参考以下文章