#查看索引
[root@localhost elasticsearch-5.4.1]# curl -XGET '128.0.0.101:9200/test/external/1?pretty&pretty'
{
"_index" : "test",
"_type" : "external",
"_id" : "1",
"_version" : 1,
"found" : true,
"_source" : {
"name" : "elk test"
}
}
#删除索引
[root@localhost elasticsearch-5.4.1]# curl -XDELETE '128.0.0.101:9200/test/external/1?pretty&pretty'
{
"found" : true,
"_index" : "test",
"_type" : "external",
"_id" : "1",
"_version" : 2,
"result" : "deleted",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
}
}
#总结格式
<REST Verb>/<Index>/<Type>/<ID>
#替换文档
[root@localhost elasticsearch-5.4.1]# curl -XPUT '128.0.0.101:9200/test/external/1?pretty&pretty' -d'
{
"name":"elk test5"
}'
{
"_index" : "test",
"_type" : "external",
"_id" : "1",
"_version" : 9,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"created" : false
}
#没创建索引并添加文档(不显示指定ID)
[root@localhost elasticsearch-5.4.1]# curl -XPOST '128.0.0.101:9200/test/external?pretty&pretty' -d'
{
"name":"elk test3"
}'
{
"_index" : "test",
"_type" : "external",
"_id" : "AWEpYQSdAcj1E5z65ZJt",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"created" : true
}
#update更新
[root@localhost elasticsearch-5.4.1]# curl -XPOST '128.0.0.101:9200/test/external/1/_update?pretty&pretty' -d'
{
"doc":{"name":"elk test5"}
}'
{
"_index" : "test",
"_type" : "external",
"_id" : "1",
"_version" : 3,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
}
}
#添加字段
[root@localhost elasticsearch-5.4.1]# curl -XPOST '128.0.0.101:9200/test/external/1/_update?pretty&pretty' -d'
{
"doc":{"name":"elk test5","age":18}
}'
{
"_index" : "test",
"_type" : "external",
"_id" : "1",
"_version" : 4,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
}
}
[root@localhost elasticsearch-5.4.1]# curl -XGET '128.0.0.101:9200/test/external/1?pretty&pretty'
{
"_index" : "test",
"_type" : "external",
"_id" : "1",
"_version" : 4,
"found" : true,
"_source" : {
"name" : "elk test5",
"age" : 18
}
}
#用脚本
[root@localhost elasticsearch-5.4.1]# curl -XPOST '128.0.0.101:9200/test/external/1/_update?pretty&pretty' -d'
{
"script":"ctx._source.age+=5"
}'
{
"_index" : "test",
"_type" : "external",
"_id" : "1",
"_version" : 5,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
}
}
#批量处理
[root@localhost elasticsearch-5.4.1]# curl -XPOST '128.0.0.101:9200/test/external/_bulk?pretty&pretty' -d'
> {"index":{"_id":"1"}}
> {"name":"elk bulk1"}
> {"index":{"_id":"2"}}
> {"name":"elk bulk2"}'
{
"took" : 9,
"errors" : false,
"items" : [
{
"index" : {
"_index" : "test",
"_type" : "external",
"_id" : "1",
"_version" : 6,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"created" : false,
"status" : 200
}
}
]
}
#更新删除
[root@localhost elasticsearch-5.4.1]# curl -XPOST '128.0.0.101:9200/test/external/_bulk?pretty&pretty' -d'
{"update":{"_id":"1"}}
{"doc":{"name":"elk bulk1 is becoming"}}
{"delete":{"_id":"2"}}'
{
"took" : 8,
"errors" : false,
"items" : [
{
"update" : {
"_index" : "test",
"_type" : "external",
"_id" : "1",
"_version" : 7,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"status" : 200
}
}
]
}