# Query fails when value is empty - how do I work around this?

**URL:** <https://discuss.elastic.co/t/query-fails-when-value-is-empty-how-do-i-work-around-this/250439>\
**Category:** Elasticsearch\
**Created:** [September 30, 2020, 2:48am UTC](https://discuss.elastic.co/t/query-fails-when-value-is-empty-how-do-i-work-around-this/250439 "2020-09-30T02:48:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![M\_Gibbs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/m_gibbs/32/45665_2.png) [@M\_Gibbs](https://discuss.elastic.co/u/M_Gibbs)\
**Post date:** [September 30, 2020, 2:48am UTC](https://discuss.elastic.co/t/query-fails-when-value-is-empty-how-do-i-work-around-this/250439/1 "2020-09-30T02:48:20Z")

</div>

Hi there,

We are parsing our query via a form, and this form has 29+ inputs.

Therefore there are many occassions where part of the full JSON query might have an empty value if the end user does not use one of the 29 + inputs.

I looked at applying null value to the index ([here](https://www.elastic.co/guide/en/elasticsearch/reference/current/null-value.html#:~:text=A%20null%20value%20cannot%20be,that%20field%20has%20no%20values.&text=Replace%20explicit%20null%20values%20with%20the%20term%20NULL%20.,be%20replaced%20with%20the%20null_value%20.))

But in further review, it looks like this won't solve the issue.

What would be the correct way for ES to essentially ignore a query string as part of the full JSON query that does not have a value, or, can I default the value to something for it to be ignore (e.g. my initial idea of using 'null'.

Appreciate any help here.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [September 30, 2020, 6:44am UTC](https://discuss.elastic.co/t/query-fails-when-value-is-empty-how-do-i-work-around-this/250439/2 "2020-09-30T06:44:58Z")

</div>

I would recommend generating the query based on the inputs provided rather than try to populate a static query template, which seems to be similar to what you are doing now.

---

<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:** [October 28, 2020, 6:45am UTC](https://discuss.elastic.co/t/query-fails-when-value-is-empty-how-do-i-work-around-this/250439/3 "2020-10-28T06:45:12Z")

</div>

Closed on October 28, 2020, 6:45am UTC

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