Aggregations : OR filter for terms within a specific field


(Hemed) #1

Hi,

Here I am trying to build an OR filter for field "assignee" using terms aggregations. Please consider the following query, the results for this query are in Case 2 below :-

"query": {

"filtered": {
    "query": {
        "query_string": {
            "query": "*"
        }
    },
    "filter": {
        "bool": {
            "must": {
                "term": {
                    "assignee": ["Eddie"]
                }
            }
        }
    }
}},"aggregations": {

"assignee": {
    "terms": {
        "field": "assignee",
        "size": 10,
        "min_doc_count": 0
    }
}, "status": {
    "terms": {
        "field": "status",
        "size": 10,
        "min_doc_count": 0
    }
}

}

Now when I run this query, all the terms in the field "assignee" are getting 0 count, except "Diddie" (See case 2)

But since it's an OR filter in this particular field "assignee", I don't want to update the count for any term in this field, so that a user may see the full list. But I want the selection to affect other aggregations that have not been selected yet. Any idea on how I can achieve this (Case 3 below)?

==EDIT==
See Case 3, selected term is "Eddie" but all the terms under "Assignee" are not updated (OR filter) but other terms in other aggregations (see "Status" ) are updated accordingly.

Case 1 (Original, No filters):Assignee : ( ) Eddie: 2 ( ) Diddie: 2 ( ) Joe: 1 Status: ( ) Sent: 3 ( ) Draft: 2

Case 2 (filter=Eddie):Assignee: (x) Eddie: 2 ( ) Diddie: 0 ( ) Joe: 0 Status: ( ) Sent: 1 ( ) Draft: 1

Case 3 (filter=Eddie):Assignee: (x) Eddie: 2 ( ) Diddie: 2 ( ) Joe: 1 Status: ( ) Sent: 1 ( ) Draft: 1


(Adrien Grand) #2

I suspect what you are after is either post_filter or global aggregations?


(Hemed) #3

I have tried but I could not get it working. I have updated my question with examples, please have a look.


(system) #4