I am trying to query index using dsl and sql method, while comparing the results i found that the values are different.Below are the query and required details.
Please don't post pictures of text, they are difficult to read, impossible to search and replicate (if it's code), and some people may not be even able to see them
It'd help a lot if you copied the queries and responses and posted them in the topic.
Query IN SQL -:
GET _sql?format=txt
{
"query":"""
SELECT docID, chargeInUSD, chargeInCntryCurr,exchangeRate FROM prv_charge_data_extract
WHERE docID in ('c806e6213793f13726ed2cdb95b439b97e5011ec','ad2a5fb4bf83f9b71947d8acf1a3a28b58d9115a')
"""
}
the bold highlighted values differs in SQL and DSL results. After i tried it many queries for different indices, i observed that the values for float datatype filed gives different result.
What you get from Elasticsearch in query DSL is the _source meaning the exact "text" those documents were indexed with. What you get from SQL is very likely to be the value that was actually indexed. Try testing the same query DSL but adding docvalue_fields to it and put there your chargeInUSD field and see what you get back. Documentation about docvalue_fields can be checked here.
@pkshara,
The difference stems from the fact that the floating point types have a discrete resolution: not all numbers within their value range can be represented with them. 472.4606038057 is such a number and the closest value that Elasticsearch JVM can assign to it is the one you got back.
You can improve the precision of your values by mapping these fields as double instead of float and that should likely cover your precision needs (but still does't rule out issues like this towards the end of the precision range, after some 15 decimal digits).
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.