# Double datatypes values returned as 0 rather than 0.0 in Elastic Search Results

**URL:** https://discuss.elastic.co/t/double-datatypes-values-returned-as-0-rather-than-0-0-in-elastic-search-results/114893
**Category:** Elasticsearch
**Created:** [January 10, 2018, 2:18pm UTC](https://discuss.elastic.co/t/double-datatypes-values-returned-as-0-rather-than-0-0-in-elastic-search-results/114893 "2018-01-10T14:18:33Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![Niranjan\_Velakanti](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niranjan_velakanti/32/26420_2.png) [@Niranjan\_Velakanti](https://discuss.elastic.co/u/Niranjan_Velakanti)
#### Post date: [January 10, 2018, 2:18pm UTC](https://discuss.elastic.co/t/double-datatypes-values-returned-as-0-rather-than-0-0-in-elastic-search-results/114893/1 "2018-01-10T14:18:33Z")

</div>

Hi  
We are in a process of migrating ES from 1.5.2 to 6.1.1 and we hit a problem.

We have an index where one of the properties is of type "double".  
The value for the property in the documents loaded into the index is 0.0.

Unfortunately when i query the index the results of the document is returned as 0, which is breaking my client code whose data type is autosuggested to long rather than double.

where as 1.5.2 version is returning 0.0.

Please suggest a solution to fix this issue

---

<div class="post-metadata">

### Author: ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)
#### Post date: [January 10, 2018, 2:21pm UTC](https://discuss.elastic.co/t/double-datatypes-values-returned-as-0-rather-than-0-0-in-elastic-search-results/114893/2 "2018-01-10T14:21:57Z")

</div>

Can you show your mapping?

```
GET your-index/_mapping
```

---

<div class="post-metadata">

### Author: ![Niranjan\_Velakanti](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niranjan_velakanti/32/26420_2.png) [@Niranjan\_Velakanti](https://discuss.elastic.co/u/Niranjan_Velakanti)
#### Post date: [January 10, 2018, 2:25pm UTC](https://discuss.elastic.co/t/double-datatypes-values-returned-as-0-rather-than-0-0-in-elastic-search-results/114893/3 "2018-01-10T14:25:52Z")

</div>

```
			{
			   "parent_code": {
				  "mappings": {
					 "doc": {
						"dynamic_templates": [
						   {
							  "strings_as_keywords": {
								 "match_mapping_type": "string",
								 "mapping": {
									"type": "keyword"
								 }
							  }
						   },
						   {
							  "row_keys_datatype": {
								 "match": "ROWKEY",
								 "mapping": {
									"type": "long"
								 }
							  }
						   }
						],
						"properties": {
						   "@timestamp": {
							  "type": "date"
						   },
						   "@version": {
							  "type": "keyword"
						   },
						   "BOTTOM_DECILE": {
							  "type": "double"
						   },
						   "BenchMark10": {
							  "type": "float"
						   },
						   "BenchMark3": {
							  "type": "float"
						   },
						   "BenchMark4": {
							  "type": "float"
						   },
						   "BenchMark5": {
							  "type": "float"
						   },
						   "BenchMark6": {
							  "type": "float"
						   },
						   "BenchMark7": {
							  "type": "float"
						   },
						   "BenchMark8": {
							  "type": "float"
						   },
						   "BenchMark9": {
							  "type": "float"
						   }
						   "EARNED_SCORE_BONUS_POINT": {
							  "type": "float"
						   },
						   "HAS_SUB_MEASURES": {
							  "type": "long"
						   },
						   "HIGH_PERFORMANCE": {
							  "type": "long"
						   }
							
						   "PAGE_ID": {
							  "type": "long"
						   },
						   "id": {
							  "type": "keyword"
						   }
						}
					 }
				  }
			   }
			}

```

I am referring to EARNED\_SCORE\_BONUS\_POINT field

---

<div class="post-metadata">

### Author: ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)
#### Post date: [January 10, 2018, 2:28pm UTC](https://discuss.elastic.co/t/double-datatypes-values-returned-as-0-rather-than-0-0-in-elastic-search-results/114893/4 "2018-01-10T14:28:09Z")

</div>

Are you sure that you're sending "0.0" in the document source ? Can you show a sample document which contains "0.0" in its source, but "0" comes back in the results ?

---

<div class="post-metadata">

### Author: ![Niranjan\_Velakanti](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niranjan_velakanti/32/26420_2.png) [@Niranjan\_Velakanti](https://discuss.elastic.co/u/Niranjan_Velakanti)
#### Post date: [January 10, 2018, 2:49pm UTC](https://discuss.elastic.co/t/double-datatypes-values-returned-as-0-rather-than-0-0-in-elastic-search-results/114893/5 "2018-01-10T14:49:30Z")

</div>

Below are links for actual Mappings, Source and results  
[Mapping](https://pastebin.com/sHA1ytJd)  
[Doc Source loaded from logstash](https://pastebin.com/w98F7tce)  
[Results](https://pastebin.com/M1LtAt39)

---

<div class="post-metadata">

### Author: ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)
#### Post date: [January 10, 2018, 3:08pm UTC](https://discuss.elastic.co/t/double-datatypes-values-returned-as-0-rather-than-0-0-in-elastic-search-results/114893/6 "2018-01-10T15:08:29Z")

</div>

The mapping you linked to is defined in the `parent_measure_code` index but the document you're showing comes from the `parent_code` index. Can you show the mapping from your `parent_code` index, too?

---

<div class="post-metadata">

### Author: ![Niranjan\_Velakanti](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niranjan_velakanti/32/26420_2.png) [@Niranjan\_Velakanti](https://discuss.elastic.co/u/Niranjan_Velakanti)
#### Post date: [January 10, 2018, 3:11pm UTC](https://discuss.elastic.co/t/double-datatypes-values-returned-as-0-rather-than-0-0-in-elastic-search-results/114893/7 "2018-01-10T15:11:02Z")

</div>

> [@val](#):
>
> parent\_code

its indeed parent\_measure\_code, I changed the index name and deleted few unwanted fields in my first post. The information I shared in the links are the actual ones

---

<div class="post-metadata">

### Author: ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)
#### Post date: [January 10, 2018, 3:14pm UTC](https://discuss.elastic.co/t/double-datatypes-values-returned-as-0-rather-than-0-0-in-elastic-search-results/114893/8 "2018-01-10T15:14:51Z")

</div>

The source you're seeing (3rd link) is really exactly what you have sent to ES. ES does never modify the source document. So we need more insights into how your indexing process looks like. Does that happen via Logstash?

---

<div class="post-metadata">

### Author: ![Niranjan\_Velakanti](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niranjan_velakanti/32/26420_2.png) [@Niranjan\_Velakanti](https://discuss.elastic.co/u/Niranjan_Velakanti)
#### Post date: [January 10, 2018, 3:20pm UTC](https://discuss.elastic.co/t/double-datatypes-values-returned-as-0-rather-than-0-0-in-elastic-search-results/114893/9 "2018-01-10T15:20:15Z")

</div>

Yes, below is the logstash Conf file link  
[Logstash](https://pastebin.com/cLsnbc31)

And the Db query always returns the results as 0.0 ,for the field in question

If you observe the "EARNED\_SCORE\_BONUS\_POINT" fields they have different values in both source and results

---

<div class="post-metadata">

### Author: ![Niranjan\_Velakanti](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niranjan_velakanti/32/26420_2.png) [@Niranjan\_Velakanti](https://discuss.elastic.co/u/Niranjan_Velakanti)
#### Post date: [January 10, 2018, 6:03pm UTC](https://discuss.elastic.co/t/double-datatypes-values-returned-as-0-rather-than-0-0-in-elastic-search-results/114893/10 "2018-01-10T18:03:07Z")

</div>

Hi, Is there a way at least to override the default behavior and return the values honoring the datatypes of the fields. May be any plugin where i can transform the json response.

Its quite urgent.

Thank you.

---

<div class="post-metadata">

### Author: ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)
#### Post date: [January 10, 2018, 6:12pm UTC](https://discuss.elastic.co/t/double-datatypes-values-returned-as-0-rather-than-0-0-in-elastic-search-results/114893/11 "2018-01-10T18:12:13Z")

</div>

One thing you might want to try is to send your field as a string (but keep the `float` type in the mapping !!) and thus the value will be unaltered when it comes back

In your Logstash config you need to add a `mutate/convert` filter

```
filter {
   mutate {
      convert => { "EARNED_SCORE_BONUS_POINT" => "string" }
   }
}

```

Then you keep your mapping as it is:

```
PUT parent_measure_code
{
  "mappings": {
    "doc": {
      "properties": {
        "EARNED_SCORE_BONUS_POINT": {
          "type": "float"
        }
      }
    }
  }
}

```

You index the document

```
PUT parent_measure_code/doc/1
{
  "EARNED_SCORE_BONUS_POINT": "0.0"
}

```

When retrieving it will get "0.0" (as a string though):

```
GET parent_measure_code/doc/1
{
  "EARNED_SCORE_BONUS_POINT": "0.0"
}

```

Not sure if that helps...

---

<div class="post-metadata">

### Author: ![Niranjan\_Velakanti](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niranjan_velakanti/32/26420_2.png) [@Niranjan\_Velakanti](https://discuss.elastic.co/u/Niranjan_Velakanti)
#### Post date: [January 10, 2018, 6:22pm UTC](https://discuss.elastic.co/t/double-datatypes-values-returned-as-0-rather-than-0-0-in-elastic-search-results/114893/12 "2018-01-10T18:22:37Z")

</div>

Thanks for the information.  
But It won't help, as there are many fields (float) whose values are 0.0 being returned as 0 across multiple docs.

I'm looking for a fix at core level by sending the appropriate json value based on the field data type, so that the json result is mapped correctly at client end.

If you any ideas to change the behavior in base code or via plugins, pls don't mind dropping drop it at [niranjan.518@gmail.com](mailto:niranjan.518@gmail.com). As said earlier, I'm in a bad need of the fix.

---

<div class="post-metadata">

### Author: ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)
#### Post date: [January 10, 2018, 6:26pm UTC](https://discuss.elastic.co/t/double-datatypes-values-returned-as-0-rather-than-0-0-in-elastic-search-results/114893/13 "2018-01-10T18:26:35Z")

</div>

On the other hand, I'm curious to know why your client side code can't cope with 0 instead of 0.0... Seems somewhat fragile...

---

<div class="post-metadata">

### Author: ![Niranjan\_Velakanti](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niranjan_velakanti/32/26420_2.png) [@Niranjan\_Velakanti](https://discuss.elastic.co/u/Niranjan_Velakanti)
#### Post date: [January 10, 2018, 8:09pm UTC](https://discuss.elastic.co/t/double-datatypes-values-returned-as-0-rather-than-0-0-in-elastic-search-results/114893/14 "2018-01-10T20:09:47Z")

</div>

The ObjectMapper class from jackson library auto detects the java datatype based on the json value from ES Results and creates the HashMap of the fields from json. So now 2 documents from same index with values of 0 and 0.0 for a given field will create 2 objects with different datatypes, Integer and Double. Which is wrong. We explicitly dont provide data type mapping while tranforming results, but rather rely on ES fields data types.

---

<div class="post-metadata">

### Author: ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)
#### Post date: [January 10, 2018, 8:28pm UTC](https://discuss.elastic.co/t/double-datatypes-values-returned-as-0-rather-than-0-0-in-elastic-search-results/114893/15 "2018-01-10T20:28:44Z")

</div>

You might want to look towards writing a custom deserializer for this.

See [https://stackoverflow.com/a/7334405/4604579](https://stackoverflow.com/a/7334405/4604579)

---

<div class="post-metadata">

### Author: ![Niranjan\_Velakanti](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niranjan_velakanti/32/26420_2.png) [@Niranjan\_Velakanti](https://discuss.elastic.co/u/Niranjan_Velakanti)
#### Post date: [January 11, 2018, 4:51pm UTC](https://discuss.elastic.co/t/double-datatypes-values-returned-as-0-rather-than-0-0-in-elastic-search-results/114893/16 "2018-01-11T16:51:37Z")

</div>

Hi, do you see this as a bug in the base code of Elastic Search ?

---

<div class="post-metadata">

### Author: ![Niranjan\_Velakanti](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/niranjan_velakanti/32/26420_2.png) [@Niranjan\_Velakanti](https://discuss.elastic.co/u/Niranjan_Velakanti)
#### Post date: [January 11, 2018, 9:22pm UTC](https://discuss.elastic.co/t/double-datatypes-values-returned-as-0-rather-than-0-0-in-elastic-search-results/114893/17 "2018-01-11T21:22:12Z")

</div>

After debugging the elastic search code, I found that the issue is with logstash elastic search plugin. ES never saw 0.0 in the source. It is the plugin that is converting 0.0 to 0 while putting the doc into the ES, but stdout prints 0.0 to console. Im still wondering about the odd behavior of the plugin to strip the .0

---

<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: [February 8, 2018, 9:22pm UTC](https://discuss.elastic.co/t/double-datatypes-values-returned-as-0-rather-than-0-0-in-elastic-search-results/114893/18 "2018-02-08T21:22:40Z")

</div>

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