Different values when trying to use scripted field

Hi, im trying to create a scripted field wich is the result of 2 different values. Thanks in advance

This is the value i got stored in my document i access it usen the get "index"/_doc/"id"
image
image

If i manually add this 2 values i get a total of: 351.53

But when i use the scripted field i get the following value:
image

And i dont know why. This is my script

image

Check the mapping of your index - I assume rotativocap is indexed as a non-floating point type (like integer). If that's the case the docvalues (which are used here to calculate the scripted field) will work with a rounded version of the value.

To fix the problem, change your mapping so rotativocap is a e.g. a double, then re-index your existing data.

It happens something curious here, take a look at this:

This is my mapping for rotativocap:
image

And this is the value stored if i access with a search:
image

But if i access from the script with the:
image

This is the value i get for rotativocap:
image

And it get yet worse becouse this is the mapping for the other one:

I dont have access to the .37

It seems like one screenshot is missing in your answer.

Yes, this behavior is expected. The value you are seeing in the search is the one from _source (the original document transmitted to Elasticsearch), but it's not what powers scripted fields. Scripted fields work with docvalues which are the indexed values based on the type in the mapping (in this case long, so 219.37 is rounded to 219).

In my previous post I mentioned how you can fix this - you need to adjust your mapping. This should be done like this:

  • Create new index with the corrected mapping
  • Use the re-index api to reindex your data from the current index into the new one with the correct mapping
  • Use the new index from now on (you can work with index aliases so you don't have to change the name everywhere)

Thank you so much for your help

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