gpt4 book ai didi

php - PHP应该是[END_OBJECT],但得到了[FIELD_NAME],可能有太多的查询子句

转载 作者:行者123 更新时间:2023-12-03 01:41:26 26 4
gpt4 key购买 nike

Elasticsearch 2.4.5
PHP 7.0

我有以下通过curl起作用的聚合查询,但是在转换为PHP时失败。我觉得自己缺少一些愚蠢/简单的东西,只是在寻找另一只眼睛

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"
}
}
}
}
}
}'

但是当我尝试将其转换为PHP时出现错误
<?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);

这是错误
$ 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

最佳答案

您的bool/must子句需要是一个数组,因此缺少一些尖括号:

    'bool' => [
'must' => [
-> [
'type' => [
'value' => 'web_logs'
]
-> ],
-> [
'range' => [
'@timestamp' => [
'gte' => '2017-10-01T00:00:00.000',
'lt' => '2017-11-01T00:00:00.000'
]
]
-> ]
],
]

关于php - PHP应该是[END_OBJECT],但得到了[FIELD_NAME],可能有太多的查询子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47211297/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com