# Range Query on Nested Keyword field

**URL:** <https://discuss.elastic.co/t/range-query-on-nested-keyword-field/166304>\
**Category:** Elasticsearch\
**Created:** [January 30, 2019, 8:43am UTC](https://discuss.elastic.co/t/range-query-on-nested-keyword-field/166304 "2019-01-30T08:43:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Morten\_Trolle](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/morten_trolle/32/40364_2.png) [@Morten\_Trolle](https://discuss.elastic.co/u/Morten_Trolle)\
**Post date:** [January 30, 2019, 8:43am UTC](https://discuss.elastic.co/t/range-query-on-nested-keyword-field/166304/1 "2019-01-30T08:43:20Z")

</div>

Hey guys,

I'm trying to run a range query on a nested keyword field, but I'm not having any luck:

```
{
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "kind": "episode"
          }
        },
        {
          "nested": {
            "path": "metas",
            "query": {
              "bool": {
                "must": [
                  {
                    "term": {
                      "metas.key": "duration"
                    }
                  },
                  {
                    "range": {
                      "metas.value": {
                        "gte": "100",
                        "lte": "200",
                        "boost": 2.0
                      }
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}

```

So I'm looking for all documents where `metas.key` is `duration` and `metas.value` is between 100-200 (formatted as string).  
My query is successful, but includes any metas.value regardless of it's value, I'm e.g. getting documents where the value is `20` etc.  
My mapping (in Ruby) looks like this:

```
indexes :metas, type: :nested do
  indexes :key, type: :keyword
  indexes :value, type: :keyword
  indexes :created_at, type: :date
  indexes :updated_at, type: :date
end
```

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [February 1, 2019, 9:24am UTC](https://discuss.elastic.co/t/range-query-on-nested-keyword-field/166304/2 "2019-02-01T09:24:01Z")

</div>

Your query looks good, I'm not sure what is going wrong. Are you able to build a recreation for this issue?

---

<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:** [March 1, 2019, 9:24am UTC](https://discuss.elastic.co/t/range-query-on-nested-keyword-field/166304/3 "2019-03-01T09:24:02Z")

</div>

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