빨리 진도 빼야하는데... -_-;


아무튼 배치처리 ...


살펴보니 용도는 대충 배치(일괄) 처리 이후, 그 결과 데이터를 벌크로 올리는 것 같고, 수정이나 삭제도 할 수 있나보다.


  1. 앞에서 다 삭제했지만, 벌크를 써서 만들어 넣어보자.

    ~]$ curl -X POST "localhost:9200/customer/_doc/_bulk?pretty" -H 'Content-Type: application/json' -d'

    > {"index":{"_id":"1"}}

    > {"name": "John Doe1111" }

    > {"index":{"_id":"2"}}

    > {"name": "Jane Doe2222" }

    > '

    {

      "took" : 11,

      "errors" : false,

      "items" : [

        {

          "index" : {

            "_index" : "customer",

            "_type" : "_doc",

            "_id" : "1",

            "_version" : 2,

            "result" : "updated",

            "_shards" : {

              "total" : 2,

              "successful" : 1,

              "failed" : 0

            },

            "_seq_no" : 18,

            "_primary_term" : 2,

            "status" : 200

          }

        },

        {

          "index" : {

            "_index" : "customer",

            "_type" : "_doc",

            "_id" : "2",

            "_version" : 2,

            "result" : "updated",

            "_shards" : {

              "total" : 2,

              "successful" : 1,

              "failed" : 0

            },

            "_seq_no" : 4,

            "_primary_term" : 2,

            "status" : 200

          }

        }

      ]

    }


    똑같은 패턴이다.
    잘 들어갔는지 보려면 조회.

    ~]$ curl -X GET "localhost:9200/customer/_doc/1?pretty"

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "1",

      "_version" : 2,

      "found" : true,

      "_source" : {

        "name" : "John Doe1111"

      }

    }


    1번

    ~]$ curl -X GET "localhost:9200/customer/_doc/2?pretty"

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "2",

      "_version" : 2,

      "found" : true,

      "_source" : {

        "name" : "Jane Doe2222"

      }

    }


    얜 2번.

    잘 들어간듯. 


  2. 대량 수정 삭제.

    ~]$ curl -X POST "localhost:9200/customer/_doc/_bulk?pretty" -H 'Content-Type: application/json' -d'

    > {"update":{"_id":"1"}}

    > {"doc": { "name": "John Doe becomes Jane Doe" } }

    > {"delete":{"_id":"2"}}

    > '

    {

      "took" : 23,

      "errors" : false,

      "items" : [

        {

          "update" : {

            "_index" : "customer",

            "_type" : "_doc",

            "_id" : "1",

            "_version" : 3,

            "result" : "updated",

            "_shards" : {

              "total" : 2,

              "successful" : 1,

              "failed" : 0

            },

            "_seq_no" : 19,

            "_primary_term" : 2,

            "status" : 200

          }

        },

        {

          "delete" : {

            "_index" : "customer",

            "_type" : "_doc",

            "_id" : "2",

            "_version" : 3,

            "result" : "deleted",

            "_shards" : {

              "total" : 2,

              "successful" : 1,

              "failed" : 0

            },

            "_seq_no" : 5,

            "_primary_term" : 2,

            "status" : 200

          }

        }

      ]

    }


    한번에 1은 수정 2는 삭제.

    후, 200이 떨어졌으니..... 

    조회.

    ~]$ curl -X GET "localhost:9200/customer/_doc/1?pretty"

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "1",

      "_version" : 3,

      "found" : true,

      "_source" : {

        "name" : "John Doe becomes Jane Doe"

      }

    }

    [ㅇㅣ름이름@서버서버명 ~]$ curl -X GET "localhost:9200/customer/_doc/2?pretty"

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "2",

      "found" : false

    }


    오케이 확인 끝.
    꼴랑 id 만으로 삭제함.


  3. 벌크는 중간 처리 내용이 실패한다고 하더라도... 중단하지 않는다. 라고해서 해봄.

    ~]$ curl -X POST "localhost:9200/customer/_doc/_bulk?pretty" -H 'Content-Type: application/json' -d'

    > {"update":{"_id":"2"}}

    > {"doc": { "name": "John Doe becomes Jane Doe" } }

    > {"update":{"_id":"1"}}

    > {"doc": { "name": "John Doe becomes Jane Doe122434" } }

    > 

    > '

    {

      "took" : 75,

      "errors" : true,

      "items" : [

        {

          "update" : {

            "_index" : "customer",

            "_type" : "_doc",

            "_id" : "2",

            "status" : 404,

            "error" : {

              "type" : "document_missing_exception",

              "reason" : "[_doc][2]: document missing",

              "index_uuid" : "4clf5AwmTQ-hruQl7EGJSg",

              "shard" : "2",

              "index" : "customer"

            }

          }

        },

        {

          "update" : {

            "_index" : "customer",

            "_type" : "_doc",

            "_id" : "1",

            "_version" : 4,

            "result" : "updated",

            "_shards" : {

              "total" : 2,

              "successful" : 1,

              "failed" : 0

            },

            "_seq_no" : 20,

            "_primary_term" : 2,

            "status" : 200

          }

        }

      ]

    }


    2번을 고치고 1번을 고치도록 했는데, 음... 그렇다.

    ~]$ curl -X GET "localhost:9200/customer/_doc/1?pretty"

    {

      "_index" : "customer",

      "_type" : "_doc",

      "_id" : "1",

      "_version" : 4,

      "found" : true,

      "_source" : {

        "name" : "John Doe becomes Jane Doe122434"

      }

    }


    1 잘 고쳐짐.


    일단 여기까지.


+ Recent posts