Range Query with % symbol


(Aldrin Ramos) #1

We would like to clarify regarding one of the functions of elastic search.
https://www.elastic.co/guide/en/elasticsearch/reference/6.2/query-dsl-query-string-query.html#_ranges

According to the documentation, by using square brackets, [ ] , you’re searching inclusively.

Our sample queries were “[49% TO 90%]” AND “[50% TO 90%]”.
But, when we ran the command, the record with 50% did not show on the first query.



#2

By inserting the documents without specifying the datatype of the field_name field in the mapping. Elasticsearch will create 2 versions of the field (text and keyword).

If you analyze the field_name field with the value "50%", it's indexed as "50" (text type).
So that means, to get the expected result, you should run the query, with the keyword version :

GET testing_with_percent/_search
{
  "query": {
    "query_string": {
      "query": "field_name.keyword: [50% TO 90%]"
    }
  }
}

or with the indexed values :

GET testing_with_percent/_search
{
  "query": {
    "query_string": {
      "query": "field_name: [50 TO 90]"
    }
  }
}

(Aldrin Ramos) #3

Thank you, klof.