Float type rounding issues

I am trying to debug a kibana display issue with an index field of type float. When I look at the data in the index directly using dev tools it appears correctly.
"balance": 10000.3675
However when I view the value through the Discover feature or attempt to display it in a CSV it gets rounded incorrectly.
"balance": 10000.368
This happens regardless of the formatting settings I choose in the index pattern/field mapping. For instance if I use the formating 0,0.000000 it will still randomly round the value instead of just adding 3 0's.
"balance": 10000.368000
Does anyone have any ideas where this rounding is coming from? I tried recreating the issue in a fresh index and can't reproduce. The only hunch i have is it is related to the data field initially containing values of type long and later being updated to contain float. However I deleted all old records and remade the index pattern (and it no longer says long,float for the type of this field, just float) but still the behavior remains unchanged. Is there some cached behavior that could still be occuring? I'm curious if anyone has experienced anything similar or knows what might be happening. Let me know if there is additional information I can provide.

Hi @etnachtman Welcome to the community.

What version are you on?

Can you share the exact mapping for that field?

Hey Stephen, thank you for responding. Do you just need the version that I get back from running GET / in the dev tools? I'm seeing "number" : "7.15.2" when running that command but still digging around to see if there is a separate version of kibana specified somewhere.

Here is a picture of the field mapping in my index pattern. You can see that the example on the right predicts the formatting will appear as I'd expect without any rounding.

If I search on that index in the Discover panel and find that specific ID you can see the rounding issue I'm experiencing. Let me know if you also need me to pull the mapping information from the dev tools or if these pictures are sufficient.
searchresult

From Dev Tool 7.15.2 is Elastic version

The Kibana Version is displayed when you Simply Go to Kibana -> Stack Management.

You did not show the mapping for that field which is the most important do you know how to get the mapping...

I see the same version in the Stack Management section.
Welcome to Stack Management 7.15.2

_mapping for this index from the dev tools:

(please try not to paste text as images... hard to see, help, debug etc...etc. paste as formatted text)

But YUP You need to use a double as the type not float as you are exceeding the significant digits of a single precision float

Also you are confusing the _source (what comes in the source json) and the fields what is index stored and showed in the Discover, Visualizations.. etc

Here follow along

What you have now

PUT discuss-test/
{
  "mappings" : {
  "properties": {
    "@timestamp": {
      "type": "date"
    },
    "balance": {
      "type": "float"
    }
  }
  }
}
POST discuss-test/_doc
{
 "@timestamp" : "2022-12-22T17:44:11.891Z",
 "balance" : 11555.7125 
}

POST discuss-test/_doc
{
 "@timestamp" : "2022-12-22T17:45:11.891Z",
 "balance" : 11666.7725 
}

GET discuss-test/_search
{
  "fields": [
    "*"
  ]
}

#Results Notice the difference between the `_source` and the `fields`

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 2,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "discuss-test",
        "_id": "xkOxPIUBrWRX1Zc6vqbo",
        "_score": 1,
        "_source": {
          "@timestamp": "2022-12-22T17:44:11.891Z",
          "balance": 11555.7125 <!------ _source what you sent
        },
        "fields": {
          "@timestamp": [
            "2022-12-22T17:44:11.891Z"
          ],
          "balance": [
            11555.713 <!- Single Precision Float :( what was stored and used
          ]
        }
      },
      {
        "_index": "discuss-test",
        "_id": "x0OxPIUBrWRX1Zc6vqb5",
        "_score": 1,
        "_source": {
          "@timestamp": "2022-12-22T17:45:11.891Z",
          "balance": 11666.7725
        },
        "fields": {
          "@timestamp": [
            "2022-12-22T17:45:11.891Z"
          ],
          "balance": [
            11666.772
          ]
        }
      }
    ]
  }
}

Now lets do it with a double

DELETE discuss-test

PUT discuss-test/
{
  "mappings" : {
  "properties": {
    "@timestamp": {
      "type": "date"
    },
    "balance": {
      "type": "double"
    }
  }
  }
}

POST discuss-test/_doc
{
 "@timestamp" : "2022-12-22T17:44:11.891Z",
 "balance" : 11555.7125 
}

POST discuss-test/_doc
{
 "@timestamp" : "2022-12-22T17:45:11.891Z",
 "balance" : 11666.7725 
}

GET discuss-test/_search
{
  "fields": [
    "*"
  ]
}


# Results Happy Days!

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 2,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "discuss-test",
        "_id": "ykOzPIUBrWRX1Zc6kaYi",
        "_score": 1,
        "_source": {
          "@timestamp": "2022-12-22T17:44:11.891Z",
          "balance": 11555.7125 <!--- Source
        },
        "fields": {
          "@timestamp": [
            "2022-12-22T17:44:11.891Z"
          ],
          "balance": [
            11555.7125 <!--- Stored Field 
          ]
        }
      },
      {
        "_index": "discuss-test",
        "_id": "y0OzPIUBrWRX1Zc6kaYu",
        "_score": 1,
        "_source": {
          "@timestamp": "2022-12-22T17:45:11.891Z",
          "balance": 11666.7725 
        },
        "fields": {
          "@timestamp": [
            "2022-12-22T17:45:11.891Z"
          ],
          "balance": [
            11666.7725
          ]
        }
      }
    ]
  }
}

And Discover

Thanks for the walkthrough examples, it all makes sense. That additional search param to display the fields seems very useful for debugging this sort of issue in the future.

My only remaining question is the best way to fix the datatype. Should I push a template matching the index pattern with the mapping for the specific fields specified as type double?

Yes

There is no way to change the mapping on existing Indices... You could create the new mapping and then re-index if you wanted to.

I'm still working with development data so free to fix the issue and delete the offending older documents. Thanks again for your help clarifying this behavior.

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