database - Finding union or intersection of buckets using elasticsearch aggregations -


i have nested aggregations , want find union or intersections of 2nd aggregations buckets based on conditions on 1st aggregation bucket results.for eg aggregation.

    "aggs": {     "events": {         "terms": {             "field": "event_name"         },         "aggs":{             "devices":{                 "terms":{                     "field": "device-id"                 }             }         }     }  } 

and result of aggregation

 "aggregations": {   "events": {      "doc_count_error_upper_bound": 0,      "sum_other_doc_count": 0,      "buckets": [         {            "key": "conversion_checkout",            "doc_count": 214,            "devices": {               "doc_count_error_upper_bound": 0,               "sum_other_doc_count": 6,               "buckets": [                  {                     "key": "9a11f243d44",                     "doc_count": 94                  },                  {                     "key": "ddcb21fd6cb",                     "doc_count": 35                  }                ]            }         },         {            "key": "action_view_product",            "doc_count": 5,            "devices": {               "doc_count_error_upper_bound": 0,               "sum_other_doc_count": 0,               "buckets": [                  {                     "key": "54e4c593",                     "doc_count": 4                  },                  {                     "key": "9a11f243d44",                     "doc_count": 1                  }               ]            }         }      ]   } 

}

now if want find devices have done action_view_product , conversion_checkout how do in aggregations?

i think want device-ids having event_names action_view_product , conversion_checkout follows-

{      "aggregations":{         "devices_agg":{            "doc_count":516,          "devices":{               "doc_count_error_upper_bound":0,             "sum_other_doc_count":0,             "buckets":[                  {                     "key":623232334,                   "doc_count":275                },                {                     "key":245454512,                   "doc_count":169                },                {                     "key":345454567,                   "doc_count":32                },                {                     "key":578787565,                   "doc_count":17                },                {                     "key":146272715,                   "doc_count":23                }             ]          }       }    } } 

the doc_count = 516 total number of documents having event_names either action_view_product or conversion_checkout , "key" in devices aggregation device-id.

if correct, below query thing you-

{    "size": 0,    "aggs": {       "devices_agg": {          "filter": {             "bool": {                "must": [                   {                      "terms": {                         "event_name": [                            "action_view_product",                            "conversion_checkout"                         ]                      }                   }                ]             }          },          "aggs": {             "devices": {                "terms": {                   "field": "device-id",                   "size": 100                }             }          }       }    } } 

let me know if got wrong.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -