2017-12-11 14 views
0

elasticsearch에서 업데이트 할 데이터가 6kk 있습니다. PHP를 사용해야합니다. 설명서를 검색 한 결과 Bulk Indexing이지만 이전 데이터를 유지하지 못했습니다.탄성 검색 부분 부분 업데이트

는 내가 가진 : 업데이트

[ 
    { 
    'name': 'Jonatahn', 
    'age' : 21 
    } 
] 

내 코드 :

$params =[ 
    "index" => "customer", 
    "type" => "doc", 
    "body" => [ 
     [ 
      "index" => [ 
       "_index" => "customer", 
       "_type" => "doc", 
       "_id" => "09310451939" 
      ] 
     ], 
     [ 
      "name" => "Jonathan" 
     ] 
    ] 
]; 

$client->bulk($params); 

을 내가 이름을 갱신하고 나이를 유지할 것으로 예상하지만, 나이가 삭제 된 ['name' => 'Jonathan']를 보낼 때. 물론 데이터별로 데이터를 업데이트 할 수는 있지만 시간이 오래 걸릴 것입니다. 다른 방법이 있습니까?

답변

0

내 오류는 "index"을 사용하는 것이지만 올바른 방법은 내가 원하는대로 수행하려면 "update"입니다.

마지막 코드는 다음과 같습니다

$params =[ 
"index" => "customer", 
"type" => "doc", 
"body" => [ 
    [ 
     "update" => [ 
    // ^^^^^^ Here I change from index to update 
      "_index" => "customer", 
      "_type" => "doc", 
      "_id" => "09310451939" 
     ] 
    ], 
    [ 
     "doc" => [ 
      "name" => "Jonathan" 
     ] 
    ] 
] 
]; 

$client->bulk($params); 

내 데이터가 이전 데이터를 유지하고 그냥 PARAMS 전달 데이터를 업데이트, 위의 코드를 사용하여.

응답 :

Array 
(
    [took] => 7 
    [timed_out] => 
    [_shards] => Array 
     (
      [total] => 5 
      [successful] => 5 
      [skipped] => 0 
      [failed] => 0 
     ) 

    [hits] => Array 
     (
      [total] => 1 
      [max_score] => 1 
      [hits] => Array 
       (
        [0] => Array 
         (
          [_index] => customer 
          [_type] => doc 
          [_id] => 09310451939 
          [_score] => 1 
          [_source] => Array 
           (
            [name] => Jonathan 
            [age] => 23 
           ) 

         ) 

       ) 

     ) 

)