Elasticsearch에선 단일 Document 별로 고유한 URL을 갖는다.
http://<호스트>:<포트>/<인덱스>/_doc/<도큐먼트 id>
http://<호스트>:<포트>/<인덱스>/<도큐먼트 타입>/<도큐먼트 id>
// my_index/_doc/1에 도큐먼트 입력
$ curl -XPUT "<http://localhost:9200/my_index/_doc/1>" -H 'Content-Type: application/json' -d'
{
"name": "Jongmin Kim",
"message": "안녕하세요 Elasticsearch"
}'
{"_index":"my_index","_type":"_doc","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}
my_index Index에 Document ID가 1인 데이터를 입력하는 예제.
// my_index/_doc/1
// 최초 입력
PUT my_index/_doc/1
{
"name":"Jongmin Kim",
"message":"안녕하세요 Elasticsearch"
}
// response 최초 입력 결과
{
"_index" : "my_index",
"_type" : "_doc",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
처음으로 도큐먼트를 입력하면 "result":"created"로 표시됨.
동일한 URL에 다른 내용의 도큐먼트를 다시 입력하게 되면 기존 도큐먼트는 삭제되고 새로운 도큐먼트로 덮어 씌워짐.
이 때 결과는 "result":"updated".
// response 재입력 결과
{
"_index" : "my_index",
"_type" : "_doc",
"_id" : "1",
"_version" : 2,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"_seq_no" : 1,
"_primary_term" : 1
}
가져올 Document의 URL을 입력하면 도큐먼트의 내용을 가져오며, 문서의 내용은 _source 항목에 나타남.
GET my_index/_doc/1