# \[PHP\] expected \[END\_OBJECT\] but got \[FIELD\_NAME\], possibly too many query clauses

**URL:** <https://discuss.elastic.co/t/php-expected-end-object-but-got-field-name-possibly-too-many-query-clauses/107047>\
**Category:** Elasticsearch\
**Created:** [November 9, 2017, 1:27pm UTC](https://discuss.elastic.co/t/php-expected-end-object-but-got-field-name-possibly-too-many-query-clauses/107047 "2017-11-09T13:27:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chrisan/32/12335_2.png) [@chrisan](https://discuss.elastic.co/u/chrisan)\
**Post date:** [November 9, 2017, 1:27pm UTC](https://discuss.elastic.co/t/php-expected-end-object-but-got-field-name-possibly-too-many-query-clauses/107047/1 "2017-11-09T13:27:15Z")

</div>

Elasticsearch 2.4.5  
PHP 7.0

I have the following aggregation query that works via curl but fails when I convert to PHP. I feel like I'm missing something stupid/easy and just looking for another set of eyes

```
curl -XPOST "http://localhost:9200/_search" -d '
{
  "size": 1,
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [
            {"type": { "value": "web_logs" }},
            {"range": {
              "@timestamp": {
                "gte": "2017-10-01T00:00:00.000" ,
                "lt": "2017-11-01T00:00:00.000"
              }
            }}
          ]
        }
      }
    }
  },
  "aggs": {
    "by_company": {
      "terms": {
        "field": "company.raw"
      },
      "aggs": {
        "total_bytes": {
          "sum": {
            "field": "sc_bytes"
          }
        }
      }
    }
  }
}' 

```

But when I try to convert it to PHP I get an error

```
<?php
ini_set('display_errors', 0);

use Elasticsearch\ClientBuilder;

require 'vendor/autoload.php';

$hosts = [
  'localhost:9200'
];

$client = ClientBuilder::create()
  ->setHosts($hosts)
  ->build();

$params['body'] = [
  'size' => 1,
  'query' => [
    'filtered' => [
      'filter' => [
        'bool' => [
          'must' => [
            'type' => [
              'value' => 'web_logs'
            ],
            'range' => [
              '@timestamp' => [
                'gte' => '2017-10-01T00:00:00.000',
                'lt' => '2017-11-01T00:00:00.000'
              ]
            ]
          ],
        ]
      ]
    ]
  ],
  'aggs' => [
    'by_company' => [
      'terms' => [
        'field' => 'company.raw'
      ],
      'aggs' => [
        'total_bytes' => [
          'sum' => [
            'field' => 'sc_bytes'
          ]
        ]
      ]
    ]
  ]
];

$results = $client->search($params);

```

Here is the error

```
$ php report2.php
PHP Fatal error: Uncaught Elasticsearch\Common\Exceptions\BadRequest400Exception: {"error":{"root_cause":[{"type":"query_parsing_exception","reason":"expected [END_OBJECT] but got [FIELD_NAME], possibly too many query clauses","index":"logstash-2017.09.11","line":1,"col":92},{"type":"query_parsing_exception","reason":"expected [END_OBJECT] but got [FIELD_NAME], possibly too many query clauses","index":"logstash-2017.09.12","line":1,"col":92},{"type":"query_parsing_exception","reason":"expected [END_OBJECT] but got [FIELD_NAME], possibly too many query clauses","index":"logstash-2017.09.13","line":1,"col":92},{"type":"query_parsing_exception","reason":"expected [END_OBJECT] but got [FIELD_NAME], possibly too many query clauses","index":"logstash-2017.09.14","line":1,"col":92},{"type":"query_parsing_exception","reason":"expected [END_OBJECT] but got [FIELD_NAME], possibly too many query clauses","index":"logstash-2017.09.15","line":1,"col":92},{"type":"query_parsing_exception","reason":"expected [END_OBJECT] but got [FIELD_NAME in /mnt/c/Users/Chris/code/logstash/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php on line 610
```

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [November 17, 2017, 10:50pm UTC](https://discuss.elastic.co/t/php-expected-end-object-but-got-field-name-possibly-too-many-query-clauses/107047/2 "2017-11-17T22:50:51Z")

</div>

You probably figured it out by now, but just in case, you are missing `[` `]` around queries in the `must` clause.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 15, 2017, 10:51pm UTC](https://discuss.elastic.co/t/php-expected-end-object-but-got-field-name-possibly-too-many-query-clauses/107047/3 "2017-12-15T22:51:34Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
