2017-12-11 27 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 
           ) 

         ) 

       ) 

     ) 

)