您的位置:首页 > 其它

elasticsearch Document相关操作记录

2016-07-12 15:03 393 查看
为了学习elasticsearch,跟着官方文档及网上例子操作了一些,整理记录下来,以供大家参考。
本文所用测试工具:火狐插件HttpRequester。

elasticsearch:2.3

----------------------------------------创建文章---------------------------------------------

PUT http://192.168.10.139:9200/megacorp/employee/1
Content-Type: application/json
{
"first_name" : "John",
"last_name" : "Smith",
"age" : 25,
"about" : "I love to go rock climbing",
"interests": [ "sports", "music" ]
}
-- response --
200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 127

{"_index":"megacorp","_type":"employee","_id":"1","_version":6,"_shards":{"total":2,"successful":1,"failed":0},"created":false}
----------------------------------------查询文章---------------------------------------------

GET http://192.168.10.139:9200/megacorp/employee/1?pretty

-- response --
200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 278

{
"_index" : "megacorp",
"_type" : "employee",
"_id" : "1",
"_version" : 6,
"found" : true,
"_source" : {
"first_name" : "John",
"last_name" : "Smith",
"age" : 25,
"about" : "I love to go rock climbing",
"interests" : [ "sports", "music" ]
}
}

----------------------------------------修改文章---------------------------------------------

PUT http://192.168.10.139:9200/megacorp/employee/1
Content-Type: application/json
{
"first_name" : "John",
"last_name" : "Smith",
"age" : 25,
"about" : "I love to go rock climbing",
"interests": [ "sports", "music" ]
}
-- response --
201 Created
Content-Type: application/json; charset=UTF-8
Content-Length: 126

{"_index":"megacorp","_type":"employee","_id":"1","_version":8,"_shards":{"total":2,"successful":1,"failed":0},"created":true}

----------------------------------------查询文章---------------------------------------------

GET http://192.168.10.139:9200/megacorp/employee/1?pretty

-- response --
200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 278

{
"_index" : "megacorp",
"_type" : "employee",
"_id" : "1",
"_version" : 8,
"found" : true,
"_source" : {
"first_name" : "John",
"last_name" : "Smith",
"age" : 25,
"about" : "I love to go rock climbing",
"interests" : [ "sports", "music" ]
}
}

----------------------------------------删除文章---------------------------------------------

DELETE http://192.168.10.139:9200/megacorp/employee/1

-- response --
200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 124

{"found":true,"_index":"megacorp","_type":"employee","_id":"1","_version":7,"_shards":{"total":2,"successful":1,"failed":0}}

----------------------------------------查询文章---------------------------------------------

GET http://192.168.10.139:9200/megacorp/employee/1

-- response --
404 Not Found
Content-Type: application/json; charset=UTF-8
Content-Length: 64

{"_index":"megacorp","_type":"employee","_id":"1","found":false}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: