엔지니어 블로그

[Elasticsearch] Python Client로 Document Update 본문

ELK/elasticsearch

[Elasticsearch] Python Client로 Document Update

안기용 2023. 11. 17. 09:46

Python으로 Elasticsearch를 다루면서 Doc를 Updqte하는 방법 실험 내용입니다.

  1. 초기 doc 구조

    "test1" : "good123",
    "test2" : "asdfd"
  2. test 내용

    Test1
    #  test1 필드는 동일, test2 필드는 내용 변경, test 필드는 새롭게 추가
    update_doc = [
         {
             "update" : {
             "_id": "123123",            
             "doc" : {
                 "test1" : "good123",
                 "test2" : "asdfds123",
                 "test" : "werwear"
             }         
         }
         }       
     ]
    => update 아님. update는 일반 필드로 잡힘
    

※부적합

Test2

test1과 조건은 동일하지만, json형태를 변경

update_doc = [
{
"_id": "123123",
"doc" : {
"test1" : "good123",
"test2" : "asdfds123",
"test" : "werwear"
}
}
]
=> 초기 인덱싱 됨. 원래 생각하는 형태로 들어감
=> 필드가 동일할 때, 값을 변경하면 잘 update가 됨