Is it ok to use only filter query in elastic search

Viewed 25

i have to query elastic search for some data and all my filters are drop down values as in they are exact matches only so i thought of using only the filter query and not any must or match query, so is there any problem with this kind of approach. in the below example i am trying to get last 15 min data where L1 is any 1 of ("XYZ","CFG") and L2 is any 1 of ( "ABC","CDE") My query looks like below :

{
"size": 20,
"sort": [
    {
        "eventTs": "desc"
    }
],
"query": {
    "bool": {
 
        "filter": [
            {
                "range": {
                    "eventTs": {
                        "gte": "now-15m",
                        "lte": "now",
                        "format": "epoch_millis",
                        "boost": 1
                    }
                }
            },
            {
                "terms": {
                    "l1": [
                        "XYZ","CFG"
                    ]
                }
            },
                {
                "terms": {
                    "l2":[
                        "ABC","CDE"
                    ]
                }
            }
        ]
    }
}

}

1 Answers

If you don't need _score which is used to show the relevant documents according to their score, you can use filter which is executed in much faster way(since calculation of score is disabled), and cached as well.

Must read query and filter context for in-depth understanding of these concepts.

Related