# Failed to convert the data type from string to float

**URL:** <https://discuss.elastic.co/t/failed-to-convert-the-data-type-from-string-to-float/126175>\
**Category:** Logstash\
**Created:** [March 30, 2018, 2:04am UTC](https://discuss.elastic.co/t/failed-to-convert-the-data-type-from-string-to-float/126175 "2018-03-30T02:04:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![terrymu](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@terrymu](https://discuss.elastic.co/u/terrymu)\
**Post date:** [March 30, 2018, 2:04am UTC](https://discuss.elastic.co/t/failed-to-convert-the-data-type-from-string-to-float/126175/1 "2018-03-30T02:04:11Z")

</div>

Hi experts,

I have met an data type converting issue. My requirement is

1. parse a xml file ------ done
2. collect some node information which i need ------ done
3. add a field to be used to retrieve it ------ done
4. convert data type of this field from string to float, need use it to draw a trend in kibana. ------ **blocking**

The input file is:

```
<?xml version="1.0" encoding="UTF-8"?>
<OMeS version="2.3">
  <PMSetup startTime="2018-03-09T07:50:00.000+01:00" interval="5">
    <PMMOResult>
      <MO dimension="network_element">
        <DN>NTAS-tas01/HOSTNAME-cbam-4c63de7aeae2460289cd4197dc7-admintd-node-0/DBTYPE-cmdb</DN>
      </MO>
      <PMTarget measurementType="DBMEAS">
        <M704B1C1>32</M704B1C1>
        <M704B1C2>216</M704B1C2>
        <M704B1C3>0</M704B1C3>
        <M704B1C4>0</M704B1C4>
      </PMTarget>
    </PMMOResult>
    <PMMOResult>
      <MO dimension="network_element">
        <DN>NTAS-tas01/HOSTNAME-cbam-4c63de7aeae2460289cd4197dc7-admintd-node-1/DBTYPE-cmdb</DN>
      </MO>
      <PMTarget measurementType="DBMEAS">
        <M704B1C1>36</M704B1C1>
        <M704B1C2>96</M704B1C2>
        <M704B1C3>0</M704B1C3>
        <M704B1C4>1</M704B1C4>
      </PMTarget>
    </PMMOResult>
    <PMMOResult>
      <MO dimension="network_element">
        ... ... (about 18 node) ... ...

```

My filter pattern is:

```
input {

        file {
                path => ["/home/admin/log/NTASlog/*xml"]
                start_position => "beginning"
                type => "pmxmllog"
                sincedb_path => "/home/admin/log/NTASlog/.sincedb_file"

                codec => multiline {
                        pattern => "<?xml version"
                        #auto_flush_interval => 5
                        #max_lines => 60000
                        what => "previous"
                        negate=> true
                }

        }

}

filter {

        if [type] == "pmxmllog" {

                xml {
                        source => "message"
                        target => "parsed"

                        xpath => [
                                "/OMeS/PMSetup/@startTime", "audit_time",
                                "/OMeS/PMSetup/PMMOResult/MO/@dimension", "ELKNE",
                                "/OMeS/PMSetup/PMMOResult/MO/DN/text()", "ELKDN",
                                "/OMeS/PMSetup/PMMOResult/PMTarget/@measurementType", "ELKPMtype",
                                "/OMeS/PMSetup/PMMOResult/PMTarget/*[contains(local-name(), 'C1')]/text()", "ELKPV1",
                                "/OMeS/PMSetup/PMMOResult/PMTarget/*[contains(local-name(), 'C2')]/text()", "ELKPV2",
                                "/OMeS/PMSetup/PMMOResult/PMTarget/*[contains(local-name(), 'C3')]/text()", "ELKPV3",
                                "/OMeS/PMSetup/PMMOResult/PMTarget/*[contains(local-name(), 'C4')]/text()", "ELKPV4",
                                "/OMeS/PMSetup/PMMOResult/PMTarget/*[contains(local-name(), 'C5')]/text()", "ELKPV5"
                        ]

                }
        }

        mutate {
                add_field => {
                                "container1" => "%{[ELKDN][0]}"
                }
                add_field => {
                                "peakvalue1" => "%{[ELKPV1][0]}"
                                "peakvalue2" => "%{[ELKPV1][1]}"
                                "peakvalue3" => "%{[ELKPV1][2]}"
                                "peakvalue4" => "%{[ELKPV1][3]}"
                }

# this convert isn't valid.
                convert => [
                                "peakvalue1" , "float",
                                "peakvalue2" , "float",
                                "peakvalue3" , "float",
                                "peakvalue4" , "float"
                ]

        }

# there is no dissect plugin
# dissect {
# convert_datatype => {
# peakvalue1 => "float"
# }
# }

        date {
                match => ["audit_time", "YYYY-MM-DD HH:MM:SS.SSS"]
                timezone => "UTC"

        }

}

output {
        elasticsearch {
                        hosts => ["localhost:9200"]
        }
}

```

the output from kibana:

 ![elk5](https://us1.discourse-cdn.com/elastic/original/3X/b/8/b8bb83e2a608af2e5537e606d09ffa44ed511a41.png)

From the output, we can see the field which named "peakvalue1" is still a string, that result I can't draw a trend with it in kibana. can you help me check it? are there some other methods to achieve my object? thank you.

---

<div class="post-metadata">

**Author:** ![vinodr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vinodr/32/28759_2.png) [@vinodr](https://discuss.elastic.co/u/vinodr)\
**Post date:** [March 30, 2018, 2:32am UTC](https://discuss.elastic.co/t/failed-to-convert-the-data-type-from-string-to-float/126175/2 "2018-03-30T02:32:41Z")

</div>

> [@terrymu](#):
>
> peakvalue1

Can you try the below for conversion:

```
 convert => {
            "peakvalue1" => "float"
            "peakvalue2" => "float"
            "peakvalue3" => "float"
            "peakvalue4" => "float"
        }

```

---

<div class="post-metadata">

**Author:** ![terrymu](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@terrymu](https://discuss.elastic.co/u/terrymu)\
**Post date:** [March 30, 2018, 5:38am UTC](https://discuss.elastic.co/t/failed-to-convert-the-data-type-from-string-to-float/126175/3 "2018-03-30T05:38:28Z")

</div>

I have do three actions,

1. I saw a similar issue and split the add\_field and convert into two mutates function.

> [@Convert String to float failed](https://discuss.elastic.co/t/convert-string-to-float-failed/32232/2):
>
> I also tried: convert =\> ["geoip.location", "float"] it doesn't works, either.

1. using the convert code format as you mentioned.

2. when the data fed completely, refresh the log pattern

 ![elk6](https://us1.discourse-cdn.com/elastic/original/3X/5/1/519d5a17ada14e8d578c620bc09e196aaea54af0.png)

Then, the convert is working well !!!!!!!!!!! it blocks me a long time!.

 ![elk7](https://us1.discourse-cdn.com/elastic/original/3X/5/0/5012245847b4df4dd577987d50d3d015457d4428.png)  
 ![elk8](https://us1.discourse-cdn.com/elastic/original/3X/7/a/7abbabd81c956aa8e72c65b0d8df9b373816fa13.png)

---

<div class="post-metadata">

**Author:** ![terrymu](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@terrymu](https://discuss.elastic.co/u/terrymu)\
**Post date:** [March 30, 2018, 5:40am UTC](https://discuss.elastic.co/t/failed-to-convert-the-data-type-from-string-to-float/126175/4 "2018-03-30T05:40:15Z")

</div>

thanks a lot for your reply.!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 27, 2018, 5:40am UTC](https://discuss.elastic.co/t/failed-to-convert-the-data-type-from-string-to-float/126175/5 "2018-04-27T05:40:44Z")

</div>

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