drjtua5953
2017-11-09 20:50
浏览 61
已采纳

PHP期望[END_OBJECT]但得到[FIELD_NAME],可能有太多查询子句

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

1条回答 默认 最新

相关推荐 更多相似问题