Elasticsearch概念及简单API调用

1、基本概念

近实时

集群、节点

索引

类型

文档

碎片和副本

2、集群监控状态API

(1)集群健康状态:

curl -XGET '192.168.111.130://9200/_cat/health?v&pretty'

(2)集群节点列表:

curl -XGET '192.168.111.130://9200/_cat/nodes?v&pretty'

3、索引API

(1)查看索引列表

curl -XGET '192.168.111.130:9200/_cat/indices?v&pretty'

(2)创建索引

curl -XPUT '192.168.111.130:9200/test?pretty&pretty'

(3)创建索引并添加文档

curl -XPUT '192.168.111.130:9200/test/external/1?pretty&pretty' -d'
{
"name":"elk test"
}'

(4)查看索引文档

curl -XGET '192.168.110.130:9200/test/external/1?pretty&pretty'

(5)删除索引

curl -XDELETE '192.168.110.130:9200/test?pretty$pretty'

(6)总结格式

<REST Verb>/<Index>/<Type>/<ID>

4、修改数据API

(1)替换文档

curl -XPUT '192.168.111.130:9200/test/external/1?pretty&pretty' -d'
{
"name":"elk test3"
}'

(2)新增文档(不指定ID名称时使用,会随机生成ID号)

curl -XPOST '192.168.111.130:9200/test/external?pretty&pretty' -d'
{
"name":"elk test10"
}'

(3)更新文档(不指定ID名称时使用,会随机生成ID号)

curl -XPOST '192.168.111.130:9200/test/external/1/_update?pretty&pretty' -d'
{
"doc":{"name":"elk test5","age":18}
}'

(4)脚本方式更新文档

curl -XPOST '192.168.111.130:9200/test/external/1/_update?pretty&pretty' -d'
{
"script":"ctx._source.age += 5"
}'

(5)删除文档

curl -XDELETE '192.168.111.130:9200/test/external/2?pretty&pretty'

(6)批量处理(添加)

curl -XPOST '192.168.111.130:9200/test/external/_bulk?pretty&pretty' -d'
{"index":{"_id":"1"}}
{"name":"ELK bulk1"}
{"index":{"_id":"2"}}
{"name":"ELK bulk2"}

(7)批量处理(更新、删除)

curl -XPOST '192.168.111.130:9200/test/external/_bulk?pretty&pretty' -d'
{"update":{"_id":"1"}}
{"doc":{"name":"ELK bulk1 is update"}}
{"delete":{"_id":"2"}}'



posted @ 2017-12-26 23:18  归来似少年  阅读(484)  评论(0编辑  收藏  举报