Es-5.0.0. range query for string field


(Hilal) #1

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",
..


(sreeram) #2

"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


(Christian Dahlqvist) #3

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.


(Hilal) #4

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


(Christian Dahlqvist) #5

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


(Hilal) #6

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.
...


(David Pilato) #7

Reindexing is fast with reindex API


(Hilal) #8

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


(Christian Dahlqvist) #9

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


(Hilal) #10

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?


(Christian Dahlqvist) #11

I would recommend normalising this before indexing it.


(Hilal) #12

Ok Thank you


(system) #13

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