# Filter on doubles rounded to integer bound values?

**URL:** <https://discuss.elastic.co/t/filter-on-doubles-rounded-to-integer-bound-values/34143>\
**Category:** Elasticsearch\
**Created:** [November 9, 2015, 11:37am UTC](https://discuss.elastic.co/t/filter-on-doubles-rounded-to-integer-bound-values/34143 "2015-11-09T11:37:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Kleiweg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/peter_kleiweg/32/5810_2.png) [@Peter\_Kleiweg](https://discuss.elastic.co/u/Peter_Kleiweg)\
**Post date:** [November 9, 2015, 11:37am UTC](https://discuss.elastic.co/t/filter-on-doubles-rounded-to-integer-bound-values/34143/1 "2015-11-09T11:37:10Z")

</div>

I have this query:

```
{
  "query": {
    "filtered": {
      "query": {
        "match": {
          "text": "ik"
        }
      },
      "filter": {
        "bool": {
          "must": [
            {
              "range": {
                "lat2": {
                  "gte": 52.6018,
                  "lte": 52.6539
                }
              }
            },
            {
              "range": {
                "lng2": {
                  "gte": 6.9766,
                  "lte": 7.0622
                }
              }
            }
          ]
        } 
      }
    }
  }
}

```

Here is one of the results :

```
{
  "_index": "twitter20151105",
  "_type": "tweets",
  "_id": "662381428399841281",
  "_score": 1.9517577,
  "_source": {
    "text": "@Regenboogschaap ik!!! Ik!!",
    "lng2": 6.08333333,
    "lat2": 52.51666667
  }
}

```

This is clearly wrong. It looks like all values are trimmed to integer values for the test of the range. All results have 6 \< lng2 \< 7 and 52 \< lat2 \< 53.  
How do I fix this?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 10, 2015, 11:24pm UTC](https://discuss.elastic.co/t/filter-on-doubles-rounded-to-integer-bound-values/34143/2 "2015-11-10T23:24:15Z")

</div>

What are those fields mapped as?

---

<div class="post-metadata">

**Author:** ![Peter\_Kleiweg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/peter_kleiweg/32/5810_2.png) [@Peter\_Kleiweg](https://discuss.elastic.co/u/Peter_Kleiweg)\
**Post date:** [November 11, 2015, 9:06am UTC](https://discuss.elastic.co/t/filter-on-doubles-rounded-to-integer-bound-values/34143/3 "2015-11-11T09:06:30Z")

</div>

I didn't use an explicit mapping.

Here is a full example, entering and querying starting with a new database.

Example 1:

```
curl -XPUT "http://localhost:9200/numtest1/data/2" -d'{"val": 1.5}'
curl -XPUT "http://localhost:9200/numtest1/data/3" -d'{"val": 2.2}'
curl -XPUT "http://localhost:9200/numtest1/data/4" -d'{"val": 2.6}'
curl -XPUT "http://localhost:9200/numtest1/data/5" -d'{"val": 3.5}'
curl -XPOST "http://localhost:9200/numtest1/data/_search?pretty" -d'
{
  "query": {
    "filtered": {
      "query": {
        "match_all": { }
      },
      "filter": {
        "range": {
          "val": {
            "gte": 2.5,
            "lte": 2.7
          }
        }
      }
    }
  }
}'

```

This gives what I would expect, only 2.6

Example 2:

```
curl -XPUT "http://localhost:9200/numtest2/data/1" -d'{"val": 0}'
curl -XPOST "http://localhost:9200/numtest2/data/_search?pretty" -d'{"query":{"match_all":{}}}'
curl -XPUT "http://localhost:9200/numtest2/data/2" -d'{"val": 1.5}'
curl -XPUT "http://localhost:9200/numtest2/data/3" -d'{"val": 2.2}'
curl -XPUT "http://localhost:9200/numtest2/data/4" -d'{"val": 2.6}'
curl -XPUT "http://localhost:9200/numtest2/data/5" -d'{"val": 3.5}'
curl -XPOST "http://localhost:9200/numtest2/data/_search?pretty" -d'
{
  "query": {
    "filtered": {
      "query": {
        "match_all": { }
      },
      "filter": {
        "range": {
          "val": {
            "gte": 2.5,
            "lte": 2.7
          }
        }
      }
    }
  }
}'

```

This gives as a result the values 2.2 and 2.6

Entering value 0 first, and querying before doing further inserts changes the outcome.

This is Elasticsearch 2.0.0

---

<div class="post-metadata">

**Author:** ![mainec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mainec/32/5557_2.png) [@mainec](https://discuss.elastic.co/u/mainec)\
**Post date:** [November 11, 2015, 11:21am UTC](https://discuss.elastic.co/t/filter-on-doubles-rounded-to-integer-bound-values/34143/4 "2015-11-11T11:21:38Z")

</div>

> [@Peter\_Kleiweg](#):
>
> I didn't use an explicit mapping.

So you are using the dynamic field mapping. Depending on the values ES sees in the documents you index it will infer their types. For more on the exact rules see here: [Dynamic field mapping | Elasticsearch Guide [2.0] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/2.0/dynamic-field-mapping.html)

When unsure which types your fields are mapped to you can retrieve the mapping for your index:

> **[Get Mapping | Elasticsearch Guide \[2.0\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/2.0/indices-get-mapping.html)**

Hope this helps,  
Isabel

---

<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:** [July 5, 2017, 11:39pm UTC](https://discuss.elastic.co/t/filter-on-doubles-rounded-to-integer-bound-values/34143/5 "2017-07-05T23:39:15Z")

</div>


