CURL 快速操作ES

2018-09-29  本文已影响0人  siyongshuai

基础说明

?后面的是可选参数

集群操作

查看集群健康状态

curl -X GET "localhost:9200/_cat/health?v"

索引操作

查看索引

curl -X GET "localhost:9200/_cat/indices?v"

创建索引

curl -X PUT "localhost:9200/customer?pretty"

删除索引

curl -X DELETE "localhost:9200/customer?pretty"

文档操作

添加文档

curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d'

{

  "name": "John Doe"

}

'

查询文档

curl -X GET "localhost:9200/customer/_doc/1?pretty"

更新文档

curl -X POST "localhost:9200/customer/_doc/1/_update?pretty" -H 'Content-Type: application/json' -d'

{

  "doc": { "name": "Jane Doe" }

}

'

添加新的字段

curl -X POST "localhost:9200/customer/_doc/1/_update?pretty" -H 'Content-Type: application/json' -d'

{

  "doc": { "name": "Jane Doe", "age": 20 }

}

'

脚本方式更新

curl -X POST "localhost:9200/customer/_doc/1/_update?pretty" -H 'Content-Type: application/json' -d'

{

  "script" : "ctx._source.age += 5"

}

'

curl -X DELETE "localhost:9200/customer/_doc/2?pretty"

批量操作

多个同类请求

curl -X POST "localhost:9200/customer/_doc/_bulk?pretty" -H 'Content-Type: application/json' -d'

{"index":{"_id":"1"}}

{"name": "John Doe" }

{"index":{"_id":"2"}}

{"name": "Jane Doe" }

'

多个不同请求

curl -X POST "localhost:9200/customer/_doc/_bulk?pretty" -H 'Content-Type: application/json' -d'

{"update":{"_id":"1"}}

{"doc": { "name": "John Doe becomes Jane Doe" } }

{"delete":{"_id":"2"}}

'

从文件加载数据集

curl -H "Content-Type: application/json" -XPOST "localhost:9200/bank/_doc/_bulk?pretty&refresh" --data-binary "@accounts.json"

样例数据

上一篇 下一篇

猜你喜欢

热点阅读