I am using Elasticsearch Java API to create indexes and write queries for search. The indexes are created on various fields. One of the field is numeric(integer) on which index is created.
Now the input we get is in form of string. We have to search all the fields for the input provided. To search on numeric field we are using
QueryBuilders.rangeQuery() method.
But when it encounters any non integer value in "to" or "from" field it throws
SearchPhaseExecutionException[Failed to execute phase [query].
nested: NumberFormatException[For input string: \"30y\"]
How can I avoid this? Its fine that we do not get any search results, but I want to avoid this Exception as there can be cases where we get non integer input.
Another option is to check all the input tokens, which I want to avoid because it will add another level of check which will impact performance.
Is there any way I can accomplish this with elasticsearch API?