Es-5.0.0. range query for string field

Hi,

I want to do query on ES. I use ES-5.0.0. AND Kibana-5.0.0.

My mapping:

PUT titub2/ihale/_mapping
{
  "properties": {
    "Fiyat" : {
      "type": "string"
    }
  }
}

and my query:

GET titub2/ihale/_search
{
  "query": {
    "bool" : {
   "filter": {
     "range" : {
    "Fiyat" : {
        "gte" : "1",
        "lt" :  "4000"
    }
}
   }
    }
  }
}

It works but results are not right. Sample results:

"Fiyat": "114900,00",
"Fiyat": "141,00",
..

"String" type is not supported in ES 5.0.
https://www.elastic.co/guide/en/elasticsearch/reference/current/string.html

Andalso,
Any specific reason for why your performing Range Filter on a field which is "String" Type ?

Thanks,
Sreeram

As your field is mapped as text (string is deprecated in 5.0) that is the correct behaviour as "1" < "114900,00" < "141,00" < "4" in string comparisons (it basically compares each character/digit from the front until the strings are no longer identical and not based on numeric value). You need to map this as a suitable numeric datatype for the range query to work the way you expect it to.

1 Like

Ok I understand. Thank you.
Can I update this field? Because datas re-index it takes too long.

Mappings of existing fields can not be updated and do require reindexing.

Ok However, I searched and found this link:
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html#updating-field-mappings

...
Updating field mappingseditIn general, the mapping for existing fields cannot be updated. There are some
exceptions to this rule. For instance:
new properties can be added to Object datatype fields.

new multi-fields can be added to existing fields.

doc_values can be disabled, but not enabled.

the ignore_above parameter can be updated.
...

Reindexing is fast with reindex API

OK.
My field:
"Fiyat": "141,00"
This is a price .
Shoul I do double type or scaled_float type mapping?

I believe scaled_float is ideal for currency fields with a fixed set of decimals.

OK.
Some data divided by commas (141,00) and Some data divided by point (14.5)
What kind of mapping should I do in this case?

I would recommend normalising this before indexing it.

Ok Thank you

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