title: Elasticsearch PHP bulk index performance vs index
body: <p>I run a benchmark on elasticsearch using elasticsearch-php.
  I compare the time taken by 10 000 index one by one vs 10 000 with bulk of 1 000 documents.</p>
  
  <p>On my vpn server 3 cores 2 Gb mem the performance is quite the same with or without bulk index. </p>
  
  <p>My php code (inspired by à post): </p>
  
  <pre><code>&lt;?php
  set_time_limit(0);  //  no timeout
  require 'vendor/autoload.php';
  $es = new Elasticsearch\Client([
      'hosts'=&gt;['127.0.0.1:9200']
  ]);
  $max = 10000;
  
  // ELASTICSEARCH BULK INDEX
  $temps_debut = microtime(true);
  for ($i = 0; $i &lt;=  $max; $i++) {
      $params['body'][] = array(
          'index' =&gt; array(
              '_index' =&gt; 'articles',
              '_type' =&gt; 'article',
              '_id' =&gt; 'cle' . $i
          )
      );
      $params['body'][] = array(
          'my_field' =&gt; 'my_value' . $i
      );
      if ($i % 1000) {   // Every 1000 documents stop and send the bulk request
          $responses = $es-&gt;bulk($params);
          $params = array();  // erase the old bulk request    
          unset($responses); // unset  to save memory
      }
  }
  $temps_fin = microtime(true);
  echo 'Elasticsearch bulk: ' . round($i / round($temps_fin - $temps_debut, 4)) . ' per sec &lt;br&gt;';
  
  // ELASTICSEARCH WITHOUT BULK INDEX
  $temps_debut = microtime(true);
          for ($i = 1; $i &lt;= $max; $i++) {    
              $params = array();
              $params['index'] = 'my_index';
              $params['type']  = 'my_type';
              $params['id']    = "key".$i;
              $params['body']  = array('testField' =&gt; 'valeur'.$i);
              $ret = $es-&gt;index($params);
          }
  $temps_fin = microtime(true);
  echo 'Elasticsearch One by one : ' . round($i / round($temps_fin - $temps_debut, 4)) . 'per sec &lt;br&gt;';
  ?&gt;
  </code></pre>
  
  <p>Elasticsearch bulk: 1209 per sec
  Elasticsearch One by one : 1197per sec </p>
  
  <p>Is there something wrong on my bulk index to obtain better performance ?</p>
  
  <p>Thank's</p>