Field with long type show integer value in table visualization

Hi,

I'm using Elastic v 7.17.3
I have data as followed:

{
        "_index" : "degradedtests",
        "_type" : "_doc",
        "_id" : "87b7eIUB8OjwSAfblzEq",
        "_score" : null,
        "_source" : {
          "testcaseName" : "HTTP Basic Authentication Connect to a HTTP authentication site and enter credentials Should enter credentials and pass to site",
          "testcaseActualRate" : 98.1,
          "testCaseAcceptablePassRate" : 99,
          "numberOfRuns" : 1000,
          "timestamp" : "2023-01-03T18:53:52.223Z"
        },
        "sort" : [
          1672772032223
        ]
      }

But when I create new table visualization I add field "testcaseActualRate" as last value I get 98.00 instead of 98.10

Can anyone help here?

Hi @ShayWeizman

What is the mapping of that field?

Remember that JSON above is the _source field not actually what is stored in the field which depends on the data type in the mapping.

If you want to see the actual fields add this to the top of your query.

fields: ["*"],

And if you already know the type is long and you give it a float properly formatted it will just truncate it...

Visualization may be using a float format.

So there's lots of possible little items here

Thanks Stephen,

The mapping for this field is Long:

I need to see it as float in the Table visualization, how it can be done?

Apologies perhaps I am a little confused ..... If you want a float you will need to change the mapping to a float

You will need to reindex your data because the field has already been indexed as a long

There is no magic fix... that field can not be "auto-converted" the precision in the field is already gone but you have the source so you can reindex or re-load the source after you fix the mapping.

How do I change the mapping? I just sent a json to elastic without specifying the fields types.

בתאריך יום ד׳, 4 בינו׳ 2023 ב-18:47 מאת Stephen Brown via Discuss the Elastic Stack <notifications@elastic.discoursemail.com>:

| stephenb Stephen Brown Elastic Team Member
January 4 |

  • | - |

ShayWeizman:

The mapping for this field is Long:

Apologies perhaps I am a little confused ..... If you want a float you will need to change the mapping to a float

You will need to reindex your data because the field has already been indexed as a long

There is no magic fix... that field can not be "auto-converted" the precision in the field is already gone but you have the source so you can reindex or re-load the source after you fix the mapping.


Visit Topic or reply to this email to respond.

To unsubscribe from these emails, click here.

This electronic communication and the information and any files transmitted with it, or attached to it, are confidential and are intended solely for the use of the individual or entity to whom it is addressed and may contain information that is confidential, legally privileged, protected by privacy laws, or otherwise restricted from disclosure to anyone else. If you are not the intended recipient or the person responsible for delivering the e-mail to the intended recipient, you are hereby notified that any use, copying, distributing, dissemination, forwarding, printing, or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please return the e-mail to the sender, delete it from your computer, and destroy any printed copy of it.

What you did is perfectly fine... but if you don't define a mapping, elasticsearch will do its best and guess... in this case, it guessed long and you wanted float.

If you are going to work with this data it is best practice, perhaps you should read a little bit about the field types.

To create a mapping take a look here

if you are going to create many indices you create an index template that will apply the mapping to any index that matches a pattern

For fields you want to aggregate like codes, status, etc... you should make them keyword types

Example mapping..

PUT /my-index-000001
{
  "mappings": {
    "properties": {
      "testcaseActualRate":    { "type": "float" },  
      "statusCode":  { "type": "keyword"  }, 
      "testName":   { "type": "keyword"  }     
    }
  }
}
1 Like

Works now, thanks a lot Stephen!!!

1 Like

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