ES使用curl操作

创建简单索引
curl -X PUT “ES_HOST:9200/fltest?pretty”

创建复杂索引
curl -XPUT “http://ES_HOST:9200/saasfoundation_logs” -H ‘Content-Type: application/json’ -d’索引json’
json文件
{“settings”:{“number_of_shards”:3,“number_of_replicas”:2},“mappings”:{“properties”:{“appCode”:{“type”:“text”,“fields”:{“keyword”:{“type”:“keyword”,“ignore_above”:256}}},“token”:{“type”:“text”,“fields”:{“keyword”:{“type”:“keyword”,“ignore_above”:256}}}}}}

删除索引
curl -XDELETE ‘http://ES_HOST:9200/fltest’

查看集群健康情况
curl http://ES_HOST:9200/_cat/health
curl ‘http://ES_HOST:9200/_cat/health?v’

查看集群节点列表
curl ‘http://ES_HOST:9200/_cat/nodes?v’

查看所有索引情况
curl http://ES_HOST:9200/_cat/indices?v

查看某个索引情况
curl http://ES_HOST:9200/_cat/indices/saasfoundation_logs?v

查看某个索引结构
curl http://ES_HOST:9200/fltest/_mapping?pretty

查看某个索引数据
curl -XGET ‘http://ES_HOST:9200/fltest/external/1?pretty’
含义:获取customer索引下类型为external,id为1的数据,pretty参数表示返回结果格式美观。

修改某个索引
curl -XPUT ‘http://ES_HOST:9200/customer/external/1?pretty’ -d ‘{“name”: “John Doe”}’
curl -XPUT ‘http://ES_HOST:9200/customer/external/1?pretty’ -d ‘{“name”: “Jane Doe”}’
上述命令语句是:先新增id为1,name为John Doe的数据,然后将id为1的name修改为Jane Doe。

索引的增删改查
curl -X :///
:REST风格的语法谓词
:节点ip
:节点端口号,默认9200
:索引名
:索引类型
:操作对象的ID号

更新数据
将id为1文档的name字段更新为Jane Doe:
curl -XPOST ‘localhost:9200/customer/external/1/_update?pretty’ -d ‘{ “doc”: { “name”: “Jane Doe”}}’
将id为1数据的name字段更新为Jane Doe同时增加字段age为20:
curl -XPOST ‘localhost:9200/customer/external/1/_update?pretty’ -d ‘{“doc”: { “name”: “Jane Doe”,“age”: 20 }}’
也可以通过一些简单的scripts来执行更新。一下语句通过使用script将年龄增加5:
curl -XPOST ‘localhost:9200/customer/external/1/_update?pretty’ -d ‘{“script” : “ctx._source.age += 5”}’

删除Customer中ID为2的数据:
curl -XDELETE ‘localhost:9200/customer/external/2?pretty’

将在一个批量操作中执行创建索引:
curl -XPOST ‘localhost:9200/customer/external/_bulk?pretty’ -d ‘{“index”:{"_id":“1”}}{“name”: “John Doe” }{“index”:{"_id":“2”}}{“name”: “Jane Doe” }’
下面语句批处理执行更新id为1的数据然后执行删除id为2的数据
curl -XPOST ‘localhost:9200/customer/external/_bulk?pretty’ -d ‘{“update”:{"_id":“1”}}{“doc”: { “name”:“John Doe becomes Jane Doe” } }{“delete”:{"_id":“2”}}’

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

独孤飞磊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值