创建简单索引
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”}}’