Filtering children by parent value in elasticsearch -


i have index 3 document types:

  • lead - have , id , type (child of account)
  • account - have id
  • payment - have , id, type , account_id (child of account)

they in parent-child relationship. want statistics lead types have (group type) , count how many payments of type have.

i came query, i'm unable filter child aggregation parent's type. query lead type

{   "query": {     "match_all": {}   },   "aggs": {     "by_type": {       "terms": {         "field": "type"       },       "aggs": {         "payments_count": {           "filter": {             "and": [               {                 "has_parent": {                   "type": "account",                   "query": {                     "filtered": {                       "query": {                         "match_all": {}                       },                       "filter": {                         "and": [                           {                             "has_child": {                               "type": "payment",                               "query": {                                 "filtered": {                                   "query": {                                     "match_all": {}                                   },                                   "filter": {                                     "and": [                                       {                                         "term": {                                           "type": ?????????                                         }                                       }                                     ]                                   }                                 }                               }                             }                           }                         ]                       }                     }                   }                 }               }             ]           }         }       }     }   } } 

in last has_child filter want know how filter children lead.type of it's parent, this:

"filter": {     "and": [       {         "term": {           "type": "$lead.type"         }       }     ] } 

also, can't inverse query due aggregations going on lead type.

any appreciated

you running query against type "lead" , if want filter on "lead.type", should first filter aggregation before stepping parent.

"payments_count": {   "filter": {     "and": [      {         "term": {           "type": "$lead.type"         }      },      {        "has_parent": {        ... 

maybe query helps little similar: term filter on nested field called id not work expected


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -