0

I am trying to implement a search request in an app with ElasticSearch.

The user type some words and those words are sent to Elastic in a json request.

To be simple the my request example is like this :

body: {
  'query': {
        'multi_match': {
            'query': 'nameValue idValue',
            'type': 'most_fields',
            'fields': ['name','id'],
        }
    },}

I get the following error :

Caused by: java.lang.NumberFormatException: For input string: "nameValue"

I understand why I get this error. It's because I am trying to search a string in a number field : id. But I would like to be able to request on a string and number at the same time.

I would also like to avoid to split the words and try to determine which word is a number and which one is a string prior to send to Elastic Search.

I tried to change my request without success.

I could change the mapping of id but it'S a number so I try to avoid this solution.

3
  • 1
    You can try to add lenient: true to your query to ignore such data-type errors. Commented Aug 6, 2018 at 16:08
  • Works for me thx Commented Aug 9, 2018 at 14:25
  • @val do you want to add your answer in order for me to close this post? Commented Aug 15, 2018 at 15:27

1 Answer 1

2

You can try to add lenient: true to your query to ignore such data-type errors.

body: {
  'query': {
        'multi_match': {
            'query': 'nameValue idValue',
            'type': 'most_fields',
            'fields': ['name','id'],
            'lenient': true                  <--- add this
        }
    },}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.