ES-5.0.0- PHP aggregations

hi, I want to do aggregation with PHP and ES-5.0.0.

my JSON CODES:

GET titubb56k/ihale/_search
{
  "size" : 0,
  "query": {
    "match": {
      "IdareKodu":  "11340073"
      }
    },
"aggs":{
    "group_by_state":{
      "terms":{
        "field": "IstekliKodu",
        "order":{
          "_count":"desc"
        }      }     }   } }

It works true:

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1083,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "group_by_state": {
      "doc_count_error_upper_bound": 8,
      "sum_other_doc_count": 399,
      "buckets": [
        {
          "key": 8637772198013,
          "doc_count": 269
        },
        {
          "key": 8637772026090,
          "doc_count": 118
        },
        {
          "key": 8637772254300,
          "doc_count": 98
        },
        {
          "key": 2667269006804,
          "doc_count": 40
        },
        {
          "key": 2667269001340,
          "doc_count": 39
        },
        {
          "key": 2667269000712,
          "doc_count": 27
        },
        {
          "key": 2667269010870,
          "doc_count": 25
        },
        {
          "key": 3400375,
          "doc_count": 24
        },
        {
          "key": 8637772000408,
          "doc_count": 23
        },
        {
          "key": 2667269000730,
          "doc_count": 21
        }      ]    }  }}

and When I did with php codes:

if($IdareKodu){
    
    $searchParams['body']['query']['match']['IdareKodu'] = $IdareKodu;
    $searchParams['body']['aggs']['group_by_state']['terms']['field']= 'IstekliKodu';
    $searchParams['body']['aggs']['group_by_state']['terms']['size']= 0;
    $searchParams['body']['aggs']['group_by_state']['terms']['order']['_count'] = "desc";
}

$searchParams['body']['sort']['id']['order'] = 'asc';

pa($searchParams);
//exit;
//pa($searchParams['body']['filter']);
br();br();br();
$sorgus = mc();br();

$queryResponse = $client->search($searchParams);

when I did query by API : http://192.168.1.36/filtreleme.php?IdareKodu=11340073

RESULT:

Fatal error:  Uncaught exception 
'Elasticsearch\Common\Exceptions\BadRequest400Exception' with message 
'{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"size
 must be positive, got 
0"}],"type":"search_phase_execution_exception","reason":"all shards 
failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"titubb56k","node":"NchqMHFlRZqnHALL4pRzUA","reason":{"type":"illegal_argument_exception","reason":"size
 must be positive, got 
0"}}],"caused_by":{"type":"illegal_argument_exception","reason":"size 
must be positive, got 0"}},"status":400}' in 
/home/admin/web/localhost.example.com/public_html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:681
Stack
 trace:
#0 
/home/admin/web/localhost.example.com/public_html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(659):
 Elasticsearch\Connections\Connection->tryDeserializeError(Array, 
'Elasticsearch\\C...')
#1 
/home/admin/web/localhost.example.com/public_html/vendor/elasticsearch/ela
 in /home/admin/web/localhost.example.com/public_html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php on line 682

What is the problem?

"reason":"size must be positive, got 0"

Isn't that obvious?

You put size on the agg, not on the search request itself.

I did:
if($IdareKodu){
$searchParams['body']['size']= 0;
$searchParams['body']['query']['match']['IdareKodu'] = $IdareKodu;
$searchParams['body']['aggs']['group_by_state']['terms']['field']= 'IstekliKodu';
$searchParams['body']['aggs']['group_by_state']['terms']['order']['_count'] = "desc";
}

However,
Eventually only records related to the $IdareKodu It is not doing aggregation.

size does not have any effect on the aggregations.

Ok I understand. Thank you.

I removed ['body'] and it worked true. ($searchParams['body']['size']= 0;)

if($IdareKodu){
    $searchParams['size']= 0;
    $searchParams['body']['query']['match']['IdareKodu'] = $IdareKodu;
    $searchParams['body']['aggs']['group_by_state']['terms']['field']= 'IstekliKodu';
    $searchParams['body']['aggs']['group_by_state']['terms']['order']['_count'] = "desc";
}

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