Avoiding multiple queries

Hi guys,

{  
   "intervals":[  
      "2017-01-01T00:00:00.000Z/2017-02-07T00:00:00.000Z"
   ],
   "granularity":"all",
   "context":{  
      "timeout":60000
   },
   "queryType": "timeseries",
   "dimension": "user_id",
   "threshold": 100000,
   "metric": "audience",
   "dataSource":"dmp-events",
   "filter": {
           "type":"and",
           "fields": [
               {  
                "type":"selector",
                "dimension":"api_key",
                "value": "bsudc787s8d687sd6fsdvdsc7dsi8"
            },
            {
                "type": "selector",
                "dimension": "flight_origin",
                "value": "YYY"
            },
            {
                "type": "selector",
                "dimension": "flight_destination",
                "value": "ZZZ"
            }
        ]
    },
   "aggregations":[  
      {  
         "type":"cardinality",
         "name":"audience",
         "fields":[  
            "user_id"
         ]
      },
      {
        "type": "count",
        "name": "total_size"
      }
   ]
}

``

Given the query above, is it possible to, given different values of YYY and ZZZ (let’s say as an array), calculate its cardinality without having to run several queries for each one of the YYY and ZZZ individually? Currently we are running one query for each pair of values, but we have to run lots of queries and we are wondering if there’s a way we can combine them in one without altering the result.

Can do this on Druid or are we forced to run the queries separately?

Thank you so much for your help and have a great day!

I think you can achieve this in a single query by using FilteredAggregator (see docs - http://druid.io/docs/latest/querying/aggregations.html)

Thank you for your response!

That is almost exactly what I was looking for, but in my case I would need to have two filters and not just one, so I’m still not able to make it work at the moment, but I’ll let you know if I can.

Thank you again and have a nice day!

To specify multiple filters with a single Aggregate you can use AND filter. see http://druid.io/docs/latest/querying/filters.html

Yeah, I just figured it out.

Thank you!