Elasticsearch 5.6 aggregation avg by terms not all buckets returned

137 Views Asked by At

I have the following query on ES 5.6 :

{
  "size": 0,
  "query": {
    "exists": {
      "field": "description.keyword"
    }
  },
  "aggs": {
    "group_by_source": {
      "terms": {
        "field": "flux.source.idname.keyword",
        "size": 1000
      },
      "aggs": {
        "description_avg": {
          "avg": {
            "script": {
              "lang": "painless",
              "source": "doc['description.keyword'].toString().length()"
            }
          }
        }
      }
    }
  }
}

Which works for what I'm trying to do (display description length avg by source) but I can only see 6 buckets as a result :

enter image description here

Any idea why ?

Thanks in advance, Julien

1

There are 1 best solutions below

1
On BEST ANSWER

{ "size": 0, "query": { "exists": { "field": "description.keyword" } }, "aggs": { "group_by_source": { "terms": { "field": "flux.source.name.keyword", "size": 1000 }, "aggs": { "description_avg": { "avg": { "script": { "lang": "painless", "source": "doc['description.keyword'].toString().length()" } } } } } } }