My sample document looks like this,

{
   "user": "adfasdk",
   "act": "Made Purchase",
   "productPrice": 5099"
}

What I want is all the unique users that satisfy a particular query.

Say for example I have the query like below, that gets all the documents 
whose productPrice is between 5000 and 10000, and whose length is between 
50, 100.  The returned documents will have repeated "user"s. I just need 
all the unique users. Do I have calculate all the unique users from this 
result myself or is it possible to do using aggregation.

{
    "query": {
        "bool": {
            "must": [
                {
                    "range": {
                        "productPrice": {
                            "gte": 5000,
                            "lte": 10000
                        }
                    }
                },
                {
                    "range": {
                        "length": {
                            "gte": 50,
                            "lte": 100
                        }
                    }
                }
            ]
        }
    },
    "_source": [
        "user"
    ]
}


Below aggregation aggregates all my documents,
{
    "aggs": {
        "unique_users": {
            "terms": {
                "field": "user"
            }
        }
    }
}
Instead I want to put my query from above into my aggregation of unique 
users.. Is it possible? Or do I have to just do my normal query and 
calculate the unique users myself from the query result?

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/7dd1fba8-a5fc-4234-9f95-88995ab9e1fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to