How to do a parent document count on a child condition in a parent child mapping?

Hello,

I'm in a Parent Child mapping and I'm actually trying to do a parent document count on a child condition.
My mapping says Parent is a Treatment and child is an event. Event document has a TYP_EVE that is an error level and i want to know how many treatment has a child that has a TYP_EVE in 1 or several values that i Specify.

I'v red the doc about improving aggregation performances, and it led me to use the filters aggregation. In fact I've tried to use this kind of aggregation but performance were too low :

   {
  "aggs": {
    "top-erreur": {
      "terms": {
        "field": "TYP_EVE.keyword",
        "size": 10
      },
      "aggs": {
        "to-answers": {
          "children": {
            "type" : "evenement" 
          }
        }
      }
    }
  }
}

So I'm trying to do this kind of requests but i'm struggling. Anyone has an idea of how i can do this or what can i experiment ?

    {
      "size": 0,
      "aggs" : {
        "messages" : {
          "filters" : {
            "other_bucket_key": "other_messages",
            "filters" : {
              "errors" :   { 
              	"match" : { 
              		"query":{
              		"has_child" : {
            			"type" : "evenement",
            			"query":{
            				"bool" : {
            					"must" : 
            					[{
            						"match":{
            						"STA_EVE" : "A"
            					}}]
            				}
            			}
            			
              }
              }}
            }
          }
        }}
      }
    }

Thanks for your help

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