Bool filter cache

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?

What ES version are you using?

Elasticsearch version is 1.5.2

{
    "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

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

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.