Number_format_exception when querying field with long type using string


(Michał Begejowicz) #1

Hi!

I have a problem with querying one of the fields in my index.
It seems to be quite similar to this: Problems with Query_String and different field types , but it's an old issue so I wanted to create new one.

Elasticsearch version is 5.3.2.

One of the fields in the index:

curl -XGET http://elastic:changeme@localhost:10200/_mapping/campaign | jq "." | grep -A 2 campaign_id
"campaign_id": {
  "type": "long"
},

Now I want to use this field and some other to search for text given by user; it might be a number (which is applicable to campaign_id field), but it can be part of the name or something else, which would not be a number. Unfortunately, if I try to query with something which is not a number, I get an error:

$ curl -XPOST http://elastic:changeme@localhost:10200/campaign/campaign/_search \
     -d '
     {
       "query": { 
         "bool": { 
           "must": [
             {
               "match": {
                 "campaign_id": {
                   "query": "test",
                   "operator": "and",
                   "analyzer": "keyword"
                 }
               }
             }
           ]
         }
       }
     }'
[...]
"caused_by": {
  "type": "number_format_exception", "reason": "For input string: \"test\""
}

Is there any way to ignore this? It's ok for me if this query just doesn't match.


(system) #2

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