Range Query on Nested Keyword field

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

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

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