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  ,会自动生成一个idcurl -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"}}
'

 

 

  • 执行高级搜索操作,如分页,排序,过滤,脚本,聚合等等

转载于:https://www.cnblogs.com/zhxdxf/p/8308568.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值