elasticsearchelasticsearch-aggregation

How Elastic Search Composite Aggregation On Whole Index And Return Whole Result


I have tried to call a Composite Aggregation in ES but return only few results, clearly, it only do the composite aggregation on 10 records.

Same ask as title: How Elastic Search Composite Aggregation On Whole Index And Return Whole Result?

Query:

enter image description here

Response:

enter image description here


Solution

  • The size parameter can be set to define how many composite buckets should be returned. Each composite bucket is considered as a single bucket, so setting a size of 10 will return the first 10 composite buckets created from the value sources. The response contains the values for each composite bucket in an array containing the values extracted from each value source. Defaults to 10.

    https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-composite-aggregation.html#_size

    GET /_search
    {
      "size": 0,
      "aggs": {
        "my_buckets": {
          "composite": {
            "size": 2,   <--- update this
            "sources": [
              { "date": { "date_histogram": { "field": "timestamp", "calendar_interval": "1d" } } },
              { "product": { "terms": { "field": "product" } } }
            ]
          }
        }
      }
    }
    

    Update:

    Here is an example:

    PUT composite/_doc/1
    {
      "product": ["foo", "bar"],
      "number": [23, 65, 76, 61, 60, 85]
    }
    
    
    GET composite/_search
    {
      "size": 0,
      "aggs": {
        "my_buckets": {
          "composite": {
            "size": 20, 
            "sources": [
              { "products": { "terms": { "field": "product.keyword" } } },
              { "numbers": { "terms": { "field": "number" } } }
            ]
          }
        }
      }
    }
    

    enter image description here