Skip to content

Instantly share code, notes, and snippets.

@hkulekci
Last active June 23, 2023 11:58
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkulekci/694e042b547939397e847c7c99b1ecdd to your computer and use it in GitHub Desktop.
Save hkulekci/694e042b547939397e847c7c99b1ecdd to your computer and use it in GitHub Desktop.
Elasticsearch Nested Array Object Size Aggregation
# images field type is nested
GET products/_search
{
  "track_total_hits": true, 
  "size": 0, 
  "aggs": {
    "counts": {
      "terms": {
        "script": "params['_source']['images'].size()",
        "size": 10
      }
    }
  }
}
@hkulekci
Copy link
Author

@ar-hosseinkhani welcome 👍

@pinturic
Copy link

can it be done without script?

@hkulekci
Copy link
Author

hkulekci commented Jun 23, 2023

@pinturic Maybe you can use value_count aggregation with field images.id. I did not try but it could work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment