1

Can someone please help me to get an aggregated count of the nested sets object in elastic search, let say if my elastic search object as :

{
  "empId":12121,
  "entities": [
    {
      "sets": [
        {
          "setId": 1
        }
      ]
    }
  ]
}

entities are the type of array which contains an another array called sets. I wanted to get the count of sets of the filtered item.

{
"query": {
  "bool": {
    "filter": [
      {
        "terms": {
          "mediaItemId": [346754750,346745565]
        }
      }
    ]
  }
},
"size": 0,
"aggs": {
  "entities_agg": {
    "sum": {
      "script": {
        "inline": "params._source.entities.sets.size()"
      }
    }
  }
}
}
Ashish Yadav
  • 350
  • 3
  • 17
  • I'm not seeing any `mediaItemId` fields in your document example... – Andrei Stefan Mar 14 '18 at 06:19
  • And please, do provide some more examples with the desired output. You gave the simplest example ever: `entities` has one `sets` which has only one value in it. Provide more complex examples with the desired output. – Andrei Stefan Mar 14 '18 at 06:20
  • We know from your [previous answer](https://stackoverflow.com/questions/49250267/how-to-get-array-count-of-nested-object-in-elastic-search/49251942?noredirect=1#comment85543346_49251942) that `entities` is `nested`, but what about `entities.sets`? What's its type? – Val Mar 14 '18 at 06:34
  • this is also nested type of array and in that array, I wanted to get a count of matched items, let say `[{ "setId": 1 },{"setId": 2 }]` in this case return me 1 if setId == 1 – Ashish Yadav Apr 11 '18 at 03:57

0 Answers0