# Elasticsearch filters

**URL:** <https://discuss.elastic.co/t/elasticsearch-filters/163453>\
**Category:** Elasticsearch\
**Created:** [January 9, 2019, 4:50am UTC](https://discuss.elastic.co/t/elasticsearch-filters/163453 "2019-01-09T04:50:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![renjiie](https://avatars.discourse-cdn.com/v4/letter/r/5fc32e/32.png) [@renjiie](https://discuss.elastic.co/u/renjiie)\
**Post date:** [January 9, 2019, 4:50am UTC](https://discuss.elastic.co/t/elasticsearch-filters/163453/1 "2019-01-09T04:50:13Z")

</div>

I will receive the filter inputs from the front-end some may be null or empty but in the elasticsearch query filter all the field should be present . How to get response even the inputs are empty for some filters ?

```
{
    "query": {
        "bool": {
            "must": {
                "match": {
                    "Abstract": "cancer"
                }
            },
            "filter": [
                {
                    "term": {
                        "Publication Type": "Review"
                    }
                },
                {
                    "range": {
                        "Date Completed": {
                            "gte": "1800",
                            "lte": "2017",
                            "format": "yyyy"
                        }
                    }
                }
            ]
        }
    }
}
```

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [January 9, 2019, 5:42am UTC](https://discuss.elastic.co/t/elasticsearch-filters/163453/2 "2019-01-09T05:42:30Z")

</div>

> [@renjiie](#):
>
> I will receive the filter inputs from the front-end some may be null or empty but in the elasticsearch query filter all the field should be present

Then you need to have some defaults that are passed in by the code.  
Either that or use a search template - [Search Template | Elasticsearch Guide [6.5] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/6.5/search-template.html)

---

<div class="post-metadata">

**Author:** ![renjiie](https://avatars.discourse-cdn.com/v4/letter/r/5fc32e/32.png) [@renjiie](https://discuss.elastic.co/u/renjiie)\
**Post date:** [January 9, 2019, 10:11am UTC](https://discuss.elastic.co/t/elasticsearch-filters/163453/3 "2019-01-09T10:11:58Z")

</div>

> [@warkolm](#):
>
> nputs from the front-end some may be null or empty but in the elasticsearch query filter all the field should be present

sorry Im new to elasticsearch could you elaborate

---

<div class="post-metadata">

**Author:** ![balumurari1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/balumurari1/32/39203_2.png) [@balumurari1](https://discuss.elastic.co/u/balumurari1)\
**Post date:** [January 9, 2019, 11:36am UTC](https://discuss.elastic.co/t/elasticsearch-filters/163453/4 "2019-01-09T11:36:07Z")

</div>

Hello,  
As per my knowledge,  
when inputs are coming from frontend ,  
i.you need to keep validations for those fields and inform the user that inputs must not be null.  
or  
ii.replace null or empty with default value.

---

<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:** [February 6, 2019, 11:36am UTC](https://discuss.elastic.co/t/elasticsearch-filters/163453/5 "2019-02-06T11:36:09Z")

</div>

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