3

The ES index contains a "PRICE" field mapped as a string (due to various reasons): e.g. "2.00" or "245.00"

Running a RANGE FROM/TO (e.g. "5" to "20") query also shows documents with prices such as "500.00", "1515.00" etc.

Does anyone have a functional solution how to circumvent these additional out of range documents from showing up?

3
  • 1
    The range in your case is a string comparison, while you need floating point comparison. Is there a way you could change the field type? Number stored as string wont help much. Alternatively, you could add another field that holds the actual boolean value? Commented Jun 26, 2013 at 9:47
  • I am trying to avoid changing the field type. But if there is no other way, then yes, it probably can be implemented. Commented Jun 26, 2013 at 13:10
  • 3
    I understand. Perhaps adding another field of floating point is an option? Commented Jun 26, 2013 at 15:23

1 Answer 1

1

You can define a new field like "PRICE_VAL" (or using multi_field "PRICE.val") and explicit map it to "float" or "double" type.

After that, index both the string value and the number value of "PRICE". Now you can do a range query on "PRICE_VAL" without touching the "PRICE" field.

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.