엔지니어 블로그

[Elasticsearch]CRUD 본문

ELK/elasticsearch

[Elasticsearch]CRUD

안기용 2022. 3. 2. 21:47

Elasticsearch CRUD 기본적인 내용

Create - PUT,POST

데이터를 입력 할 때는 PUT 메서드를 사용한다.

아래의 예는 이름이 my_index인 Index에 document id가 1일 데이터를 입력하는 내용이다.

PUT my_index/_doc/1
{
  "name":"ankiyong",
  "text":"HELLO!!"
}

동일한 URL에 다른 내용을 다시 입력하게 되면 기존의 document는 삭제되고 새로운 내용으로 덮어씌워지게 된다.

즉 PUT는 Update기능도 같이 할 수 있다.

 

Read - GET

데이터를 조회할 때는 GET 메서드를 사용한다. 

GET my_index/_doc/1

 

Update - POST

POST 메서드는 PUT와 매우 유사하게 데이터 입력에 사용이 가능하다.

PUT는 document 번호를 줘야하고 POST는 안줘도 자동으로 부여한다.

POST my_index/_doc
{
  "name":"Jongmin Kim",
  "message":"안녕하세요 Elasticsearch"
}

Delete - DELETE

데이터를 삭제할 때는 DELETE 메서드를 사용한다.

DELETE my_index/_doc/1

 

 

 

'ELK > elasticsearch' 카테고리의 다른 글

[Elasticsearch] Elasticsearch nori-plugin 실험  (0) 2023.03.27
[Elasticsearhc] Enrich  (0) 2022.07.20
[Elasticsearch] minimum should match  (0) 2022.07.20
[Elasticsearch] reindex  (0) 2022.07.20
[Elasticsearch] 동의어 사전  (0) 2022.05.19