# Elastic 7.10 field type "version"

**URL:** <https://discuss.elastic.co/t/elastic-7-10-field-type-version/252545>\
**Category:** Elasticsearch\
**Created:** [October 19, 2020, 12:56pm UTC](https://discuss.elastic.co/t/elastic-7-10-field-type-version/252545 "2020-10-19T12:56:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![videns](https://avatars.discourse-cdn.com/v4/letter/v/ebca7d/32.png) [@videns](https://discuss.elastic.co/u/videns)\
**Post date:** [October 19, 2020, 12:56pm UTC](https://discuss.elastic.co/t/elastic-7-10-field-type-version/252545/1 "2020-10-19T12:56:22Z")

</div>

First, create new index with mappings, one field has type "version":

```auto
curl -X PUT "localhost:9200/version_test_v2?pretty" -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "properties": {
      "version": {         
          "type": "version"
        }
    }
  }
}
'

```

And index one document:

```auto
curl -X POST "localhost:9200/version_test_v2/_doc/?pretty" -H 'Content-Type: application/json' -d'
{
"version": "20.04"
}
'

```

And when I try to search by version range with such query:

```auto
{
  "query": {
    "range": {
      "version": {
        "gt": "79.4"
      }
    }
  },
  "explain": true
}

```

And indexed element returned in result of this query, but wrong, because 20.04 \< 79.4  
Explanation doesn't help much:

```auto
"description": "version:{[1 82 37 39 2e 1 81 34 3] TO *]"

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 19, 2020, 2:30pm UTC](https://discuss.elastic.co/t/elastic-7-10-field-type-version/252545/2 "2020-10-19T14:30:43Z")

</div>

I can reproduce this behavior. It looks like to me a bug. @cbuescher WDYT? Here is the full script:

```auto
DELETE /test 
PUT /test
{
  "mappings": {
    "properties": {
      "version": {         
          "type": "version"
        }
    }
  }
}
POST /test/_doc
{
  "version": "20.04"
}
GET /test/_search
{
  "query": {
    "range": {
      "version": {
        "gt": "79.4"
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 19, 2020, 2:32pm UTC](https://discuss.elastic.co/t/elastic-7-10-field-type-version/252545/3 "2020-10-19T14:32:43Z")

</div>

Actually when you change `20.04` with `20.4` this works well:

```auto
DELETE /test 
PUT /test
{
  "mappings": {
    "properties": {
      "version": {         
          "type": "version"
        }
    }
  }
}
POST /test/_doc
{
  "version": "20.4"
}
GET /test/_search
{
  "query": {
    "range": {
      "version": {
        "gt": "79.4"
      }
    }
  }
}

```

Gives:

```auto
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : []
  }
}

```

---

<div class="post-metadata">

**Author:** ![videns](https://avatars.discourse-cdn.com/v4/letter/v/ebca7d/32.png) [@videns](https://discuss.elastic.co/u/videns)\
**Post date:** [October 19, 2020, 2:45pm UTC](https://discuss.elastic.co/t/elastic-7-10-field-type-version/252545/4 "2020-10-19T14:45:03Z")

</div>

Yes, also find this behaviour now. But while index document don't receive any error about non-valid version format.

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [October 19, 2020, 3:00pm UTC](https://discuss.elastic.co/t/elastic-7-10-field-type-version/252545/5 "2020-10-19T15:00:11Z")

</div>

> [@videns](#):
>
> `20.04`  
> But while index document don't receive any error about non-valid version format.

This is the reason this works unexpected for you. "20.04" is not a valid version according to Semver ([www.semver.org](http://www.semver.org)). Leading zeros are not allowed in major, minor or patch. We chose to treat "shorter" version string that otherwise satisfy the Semver definition as "valid" (that is why 79.4 an 20.4 are treated as valid).  
The docs state that we accept "invalid" versions such as "20.04" at index time. This is done to make it possible for users of the old "keyword" field that used to be used a lot for version data can transition to the new field type without disruption. However, "invalid" versions will be sorted [_after_ all valid ones](https://www.elastic.co/guide/en/elasticsearch/reference/7.10/version.html), hence "79.4" \< "20.04" here.

---

<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:** [November 16, 2020, 3:00pm UTC](https://discuss.elastic.co/t/elastic-7-10-field-type-version/252545/6 "2020-11-16T15:00:12Z")

</div>

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