Elasticsearch API 문서 생성

(Elasticsearch API - Document 생성에서 넘어옴)

1 개요[ | ]

Elasticsearch API - Document 생성

2 id 지정[ | ]

  • id를 1로 지정하는 경우 (PUT 메소드 사용)
  • 만약 해당 id가 이미 있다면, 내용이 갱신된다.
testuser@localhost:~$ curl -u elastic:elastic -X PUT localhost:9200/twitter/_doc/1?pretty -H 'Content-Type: application/json' -d '{"counter":1,"tags":["red"]}'
{
  "_index" : "twitter",
  "_type" : "_doc",
  "_id" : "1",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}
testuser@localhost:~$ curl -u elastic:elastic -X GET localhost:9200/twitter/_doc/1?pretty
{
  "_index" : "twitter",
  "_type" : "_doc",
  "_id" : "1",
  "_version" : 1,
  "_seq_no" : 0,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "counter" : 1,
    "tags" : [
      "red"
    ]
  }
}

3 id 미지정[ | ]

  • id를 지정하지 않는 경우 (POST 메소드)
  • 임의의 20자리[1] id가 생성된다.
testuser@localhost:~$ curl -u elastic:elastic -X POST localhost:9200/twitter/_doc/?pretty -H 'Content-Type: application/json' -d '{"hello":1234,"tags":["world"]}'
{
  "_index" : "twitter",
  "_type" : "_doc",
  "_id" : "Cl3BAG4BMPU-sjNKB90v",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 1,
  "_primary_term" : 1
}
testuser@localhost:~$ curl -u elastic:elastic -X GET localhost:9200/twitter/_doc/Cl3BAG4BMPU-sjNKB90v?pretty
{
  "_index" : "twitter",
  "_type" : "_doc",
  "_id" : "Cl3BAG4BMPU-sjNKB90v",
  "_version" : 1,
  "_seq_no" : 1,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "hello" : 1234,
    "tags" : [
      "world"
    ]
  }
}

4 같이 보기[ | ]

5 참고[ | ]

  1. 형식: 영숫자 11자리 + - + 영숫자 8자리
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}