title: elasticsearch-php update returns bad request where curl does not
body: <p>I have a frustrating elasticsearch problem where I try to update an index. Whatever I try it just returns "Bad request" (stack below) whilst the update works well with cURL. I've tried to do the update call with both $u['body'] as JSON and as an array.</p>
  
  <p>This works fine:</p>
  
  <pre><code>curl -XPOST 'http://localhost:9200/my_index/twitter/555805761389867009/_update' -d '{"doc": {"_located":"1","country_code":"IL"}}'
  </code></pre>
  
  <p>This code, howerever:</p>
  
  <pre><code>&lt;?php
    require 'vendor/autoload.php';
    require 'db.php';
  
    $q = "SELECT * FROM countries";
    $res = mysql_query($q) or die(mysql_error());
    while($row = mysql_fetch_array($res)) {
      $find[] = "/.*?".$row['c_name'].".*?/imUs";
      $replace[] = $row['c_short'];
    }
    $client = new Elasticsearch\Client();
  
    $tmp['index'] = "my_index";
    $tmp['type'] = "twitter";
    $tmp['body']['query']['match']['_located'] = 0;
    $tmp['fields'] = 'text';
    $tmp['size'] = 100;
    $store = $client-&gt;search($tmp);
    foreach($store['hits']['hits'] as $field) {
      if($m = preg_replace($find,$replace,$field['fields']['text'][0])) {
        if(strlen($m)==2) {
          unset($u);
          $u['index'] = 'my_index';
          $u['type'] = 'twitter';
          $u['id'] = $field['_id'];
          $u['body'] = json_encode(array('_located'=&gt;"1", "country_code"=&gt;$m));
          print_r($u);
          $client-&gt;update($u);
          die();
        }
      }
    }
  ?&gt;
  </code></pre>
  
  <p>Returns:</p>
  
  <pre><code>Array
  (
      [index] =&gt; my_index
      [type] =&gt; twitter
      [id] =&gt; 555805761389867009
      [body] =&gt; {"_located":"1","country_code":"IL"}
  )
  
  PHP Fatal error:  Uncaught exception 'Guzzle\Http\Exception\ClientErrorResponseException' with message 'Client error response
  [status code] 400
  [reason phrase] Bad Request
  [url] http://localhost:9200/my_index/twitter/555805761389867009/_update' in /home/martin/el-test/elasticsearch-php/vendor/guzzle/http/Guzzle/Http/Exception/BadResponseException.php:43
  Stack trace:
  #0 /home/martin/el-test/elasticsearch-php/vendor/guzzle/http/Guzzle/Http/Message/Request.php(145): Guzzle\Http\Exception\BadResponseException::factory(Object(Guzzle\Http\Message\EntityEnclosingRequest), Object(Guzzle\Http\Message\Response))
  #1 [internal function]: Guzzle\Http\Message\Request::onRequestError(Object(Guzzle\Common\Event), 'request.error', Object(Symfony\Component\EventDispatcher\EventDispatcher))
  #2 /home/martin/el-test/elasticsearch-php/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php(164): call_user_func(Array, Object(Guzzle\Common\Event), 'request.error', Object(Symfony\Component\EventDispatcher\EventDispatcher))
  #3  in /home/martin/el-test/elasticsearch-php/src/Elasticsearch/Connections/GuzzleConnection.php on line 271
  </code></pre>