# It is possible to use two filters within a query in NodeJs?

**URL:** <https://discuss.elastic.co/t/it-is-possible-to-use-two-filters-within-a-query-in-nodejs/276029>\
**Category:** Elasticsearch\
**Created:** [June 15, 2021, 3:39pm UTC](https://discuss.elastic.co/t/it-is-possible-to-use-two-filters-within-a-query-in-nodejs/276029 "2021-06-15T15:39:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebastian\_Marroquin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sebastian_marroquin/32/90069_2.png) [@Sebastian\_Marroquin](https://discuss.elastic.co/u/Sebastian_Marroquin)\
**Post date:** [June 15, 2021, 3:39pm UTC](https://discuss.elastic.co/t/it-is-possible-to-use-two-filters-within-a-query-in-nodejs/276029/1 "2021-06-15T15:39:09Z")

</div>

Hello everybody.  
I was wondering if it is possible to have within a variable in NodeJs two types of filters, for example:

```auto
query = {
                                    "bool": {
                                        "must": [
                                            {
                                            	"multi_match" : {
                                                    "query": strQuery + "~", 
                                                    "fields": ["strDescription^10", "strCategory^30", "strSubCategory^40"],
                                                    "type": "best_fields",
                                                    "operator": "or",
                                                    "fuzziness": "auto"
                                                },
                                            },
                                           // In this part I want to add a filter for synonyms.
                                            {
                                                "bool":{
                                                    "should":[
                                                        {
                                                            range: {
                                                                "intExistenceOmicron" : {
                                                                    gt:0
                                                                }
                                                            }
                                                        },
                                                        {
                                                            range: {
                                                                "intExistence" : {
                                                                    gt:0
                                                                }
                                                            }
                                                        }
                                                    ]
                                                }
                                            }
                                        ],
                                        "must_not": {
                                            "term": {
                                                "strImage": ""
                                            }
                                        },
                                        "minimum_should_match" : "50%"
                                    }
                                };

```

I developed the filter for synonyms as follows:

```auto
 query = {
                                    "bool": {
                                        "must": [
                                            {
                                                "multi_match": {
                                                    "query": strQuery + "~",
                                                    "fields": ["strDescription^10", "strCategory^30", "strSubCategory^40", "strVendorPart"],
                                                    "minimum_should_match": "95%",
                                                    "analyzer" : "elastic_synonym_analyzer"
                                                },
                                            },
                                            {
                                                "bool": {
                                                    "should": [
                                                        {
                                                            range: {
                                                                "intExistenceOmicron":
                                                                {
                                                                    gt: 0
                                                                }
                                                            }
                                                        },
                                                        {
                                                            range: {
                                                                "intExistence":
                                                                {
                                                                    gt: 0
                                                                }
                                                            }
                                                        }
                                                    ]
                                                }
                                            }
                                        ],
                                        "must_not": {
                                            "term": {
                                                "strImage": ""
                                            }
                                        },
                                        "minimum_should_match": "95%"
                                    }
                                };

```

What I want to achieve is that I do the search first using synonyms, if you do not find any synonyms use the type filter: "best\_fields"

Thank you very much for the help 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 13, 2021, 3:39pm UTC](https://discuss.elastic.co/t/it-is-possible-to-use-two-filters-within-a-query-in-nodejs/276029/2 "2021-07-13T15:39:42Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
