elasticsearch Document相关操作记录

为了学习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}

你可能感兴趣的:(全文检索)