Bool filter cache


(Shahar Mor) #1

Hi,

If i have to use mutliple filters inside a BOOL filter, which one should i use:

{
    "filtered": {
        "filter": {
            "bool": {
                "must": [
                    {
                        "term": {
                            "_cache": true,
                            "tag": "first"
                        }
                    },
                    {
                        "term": {
                            "_cache": true,
                            "tag": "second"
                        }
                    }
                ]
            }
        }
    }
}

OR

{
    "filtered": {
        "filter": {
            "bool": {
                "_cache": true,
                "must": [
                    {
                        "term": {
                            "tag": "first"
                        }
                    },
                    {
                        "term": {
                            "tag": "second"
                        }
                    }
                ]
            }
        }
    }
}

And what are the differences?


(Clay Gorman) #2

What ES version are you using?


(Shahar Mor) #3

Elasticsearch version is 1.5.2


(Clay Gorman) #4
{
    "filtered": {
        "filter": {
            "bool": {
                "_cache": true,
                "must": [
                    {
                        "term": {
                            "tag": "first"
                        }
                    },
                    {
                        "term": {
                            "tag": "second"
                        }
                    }
                ]
            }
        }
    }
}

I believe that is the only valid option of the two you provided.

I recommend the sense plugin


(Shahar Mor) #5

Why do you believe that? I think the other one is valid as well.


(Adrien Grand) #6

Right both options work. The difference is that the first approach will cache both clauses individually and recompute the intersection every time while the second one will cache the result of the bool query directly.

Note that the _cache option does not exist anymore in elasticsearch 2.0: elasticsearch makes its own decisions regarding what to cache based on what filters are reused.


(system) #7