Skip to content

Commit 40a3a89

Browse files
committed
[BUGFIX] Prevent error when counting using existing query
Avoid errors for count requests when certain unsupported fields are present in the request.
1 parent 46a2bbc commit 40a3a89

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

Classes/Flowpack/ElasticSearch/ContentRepositoryAdaptor/Eel/ElasticSearchQueryBuilder.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ class ElasticSearchQueryBuilder implements QueryBuilderInterface, ProtectedConte
6262
*/
6363
protected $from;
6464

65+
/**
66+
* These fields are not accepted in a count request and must therefore be removed before doing so
67+
*
68+
* @var array
69+
*/
70+
protected $unsupportedFieldsInCountRequest = array('fields', 'sort', 'from', 'size');
71+
6572
/**
6673
* The ElasticSearch request, as it is being built up.
6774
* @var array
@@ -419,7 +426,14 @@ public function execute() {
419426
*/
420427
public function count() {
421428
$timeBefore = microtime(TRUE);
422-
$response = $this->elasticSearchClient->getIndex()->request('GET', '/_count', array(), json_encode($this->request));
429+
$request = $this->request;
430+
foreach ($this->unsupportedFieldsInCountRequest as $field) {
431+
if (isset($request[$field])) {
432+
unset($request[$field]);
433+
}
434+
}
435+
436+
$response = $this->elasticSearchClient->getIndex()->request('GET', '/_count', array(), json_encode($request));
423437
$timeAfterwards = microtime(TRUE);
424438

425439
$treatedContent = $response->getTreatedContent();

0 commit comments

Comments
 (0)