ES 集群管理及基本操作

通过REST API管理集群

  • 检查群集,节点和索引运行状况,状态和统计信息
查看集群健康状况 [root@lv120 elasticsearch]# curl -XGET 'http://10.45.157.120/_cat/health?v'
查看节点 [root@lv120 elasticsearch]# curl -XGET 'http://10.45.157.120:9200/_cat/nodes?v'
查看所有索引 [root@lv120 elasticsearch]# curl -XGET 'http://10.45.157.120:9200/_cat/indices?v'

 

  • 管理群集,节点和索引数据和元数据
  • 对索引执行CRUD(创建,读取,更新和删除)和搜索操作
创建索引 curl -XPUT 'localhost:9200/customer/doc/1?pretty&pretty' -H 'Content-Type: application/json' -d'
{
"name": "John Doe"
}‘
post插入  没有指定id  ,会自动生成一个id curl -XPOST 'localhost:9200/customer/doc?pretty&pretty' -H 'Content-Type: application/json' -d'
{
"name": "Jane Doe"
}
'
读取 [curl -XGET 'localhost:9200/customer/doc/1?pretty&pretty'

删除 curl -XDELETE 'localhost:9200/customer?pretty&pretty'
更新文档-修改一个field值 curl -XPOST 'localhost:9200/customer/doc/1/_update?pretty&pretty' -H 'Content-Type: application/json' -d'
{
"doc": { "name": "Jane Doe" }
}
'
 更新文档-添加一个field

curl -XPOST 'localhost:9200/customer/doc/1/_update?pretty&pretty' -H 'Content-Type: application/json' -d'
{
"doc": { "name": "Jane Doe", "age": 20 }
}
'

 更新文档-脚本操作field值(当前文档age+5)  

curl -XPOST 'localhost:9200/customer/doc/1/_update?pretty&pretty' -H 'Content-Type: application/json' -d'
{
"script" : "ctx._source.age += 5"
}
'

批量操作-新增

curl -XPOST 'localhost:9200/customer/doc/_bulk?pretty&pretty' -H 'Content-Type: application/json' -d'
{"index":{"_id":"1"}}
{"name": "John Doe" }
{"index":{"_id":"2"}}
{"name": "Jane Doe" }
'

批量操作-删除修改

(批量操作中一个失败,后面会继续执行,

返回每个操作的执行情况)

curl -XPOST 'localhost:9200/customer/doc/_bulk?pretty&pretty' -H 'Content-Type: application/json' -d'
{"update":{"_id":"1"}}
{"doc": { "name": "John Doe becomes Jane Doe" } }
{"delete":{"_id":"2"}}
'

 

 

  • 执行高级搜索操作,如分页,排序,过滤,脚本,聚合等等
posted @ 2018-01-18 09:26  猪朵朵  阅读(341)  评论(0编辑  收藏  举报