# ES version range comparision is not working as expected semantic version comparison

**URL:** <https://discuss.elastic.co/t/es-version-range-comparision-is-not-working-as-expected-semantic-version-comparison/312904>\
**Category:** Elasticsearch\
**Created:** [August 25, 2022, 10:24am UTC](https://discuss.elastic.co/t/es-version-range-comparision-is-not-working-as-expected-semantic-version-comparison/312904 "2022-08-25T10:24:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Krishna\_Sailesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/krishna_sailesh/32/110056_2.png) [@Krishna\_Sailesh](https://discuss.elastic.co/u/Krishna_Sailesh)\
**Post date:** [August 25, 2022, 10:24am UTC](https://discuss.elastic.co/t/es-version-range-comparision-is-not-working-as-expected-semantic-version-comparison/312904/1 "2022-08-25T10:24:18Z")

</div>

Hi Folks

I have a version mapping field data type with the property name "softwareVersion" in the Elasticsearch index. I have "softwareVersion" property values like Z100, Z300, 6.7, 7.0(3)I7(3), and 6.8.9

when I search with range query on "softwareVersion" field is giving results as this.

**Query:**  
curl -X GET "localhost:9200/my\_index/\_search?pretty" -H 'Content-Type: application/json' -d '{"query": {"range": {"softwareVersion": {"lte": "8.0.7" } } } }'

**result**  
the result contains data having version  
6.7, 6.8.9

1.My question is **why results are not contained with softwareVersion 7.0(3)I7(3) ?**

**Query:**  
curl -X GET "localhost:9200/my\_index/\_search?pretty" -H 'Content-Type: application/json' -d '{"query": {"range": {"softwareVersion": {"lte": "Z500" } } } }'

**result**  
the result contains data having version  
Z100, Z300, 6.7, 7.0(3)I7(3), and 6.8.9

but when I hit the below query the results are not as expected which are  
**Query:**  
curl -X GET "localhost:9200/my\_index/\_search?pretty" -H 'Content-Type: application/json' -d '{"query": {"range": {"softwareVersion": {"lte": "Z1000" } } } }'

**result**  
the result contains data having version  
Z100, 6.7, 7.0(3)I7(3), and 6.8.9

2.My question is \*\* why is Z300 not in the result of the above query?\*\*

I am using the Elasticsearch 7.10.2 version and mapping of the "softwareVersion" field as below.

_"softwareVersion": {_

- 

```
     "type": "version"*

```

- 

```
   }*

```

Thanks & Regards  
Krishna Jalla

---

<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:** [August 25, 2022, 10:24am UTC](https://discuss.elastic.co/t/es-version-range-comparision-is-not-working-as-expected-semantic-version-comparison/312904/2 "2022-08-25T10:24:18Z")

</div>

Elasticsearch 7.10 is [EOL](https://www.elastic.co/support/eol) and no longer supported. Please upgrade ASAP.

(This is an automated response from your friendly Elastic bot. Please report this post if you have any suggestions or concerns :elasticheart: )

---

<div class="post-metadata">

**Author:** ![Krishna\_Sailesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/krishna_sailesh/32/110056_2.png) [@Krishna\_Sailesh](https://discuss.elastic.co/u/Krishna_Sailesh)\
**Post date:** [August 29, 2022, 6:04am UTC](https://discuss.elastic.co/t/es-version-range-comparision-is-not-working-as-expected-semantic-version-comparison/312904/3 "2022-08-29T06:04:04Z")

</div>

are you suggesting upgrading the version? I think..the above issue is not related to the version. the problem is about version field type comparison.

Thanks  
Krishna Jalla

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [August 29, 2022, 6:22am UTC](https://discuss.elastic.co/t/es-version-range-comparision-is-not-working-as-expected-semantic-version-comparison/312904/4 "2022-08-29T06:22:42Z")

</div>

I have not used this field type, but looking at the docs it seems it assumes semantic versioning is used. As far as I can see `Z100`, `Z300,` and `7.0(3)I7(3)` does not follow the semantic versioning scheme. I am not sure what the expected behaviour is in this case, so will leave it to someone with knowledge of the internals to answer that.

I do not know if any bugs around this feature have been fixed in newer versions, but would always recommend upograding to the latest version.

---

<div class="post-metadata">

**Author:** ![Krishna\_Sailesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/krishna_sailesh/32/110056_2.png) [@Krishna\_Sailesh](https://discuss.elastic.co/u/Krishna_Sailesh)\
**Post date:** [September 12, 2022, 6:50am UTC](https://discuss.elastic.co/t/es-version-range-comparision-is-not-working-as-expected-semantic-version-comparison/312904/5 "2022-09-12T06:50:11Z")

</div>

Hi [Christian](https://discuss.elastic.co/u/Christian_Dahlqvist)

can you please suggest to me which version of Elasticsearch should I need to upgrade?

Thanks  
Krishna Jalla

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [September 12, 2022, 7:13am UTC](https://discuss.elastic.co/t/es-version-range-comparision-is-not-working-as-expected-semantic-version-comparison/312904/6 "2022-09-12T07:13:45Z")

</div>

If your versions do not follow semantic versioning, which is what is supported by this field type, why would upgrading Elasticsearch solve this?

---

<div class="post-metadata">

**Author:** ![Krishna\_Sailesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/krishna_sailesh/32/110056_2.png) [@Krishna\_Sailesh](https://discuss.elastic.co/u/Krishna_Sailesh)\
**Post date:** [September 13, 2022, 6:47am UTC](https://discuss.elastic.co/t/es-version-range-comparision-is-not-working-as-expected-semantic-version-comparison/312904/7 "2022-09-13T06:47:56Z")

</div>

@Christian_Dahlqvist  
thanks for the reply  
Yes, the versions do not follow semantic versioning. then the resource in search should not contain those versions, right? I have a lot of invalid semantic versions in DB but can I please know in the above queries what basis/ rule elasticsearch follows in case of invalid semantic versions?

for \<= Z500 results are Z100, Z300, 6.7, 7.0(3)I7(3), and 6.8.9  
but for \<= Z1000 results are Z100, 6.7, 7.0(3)I7(3), and 6.8.9

in Z1000 one why Z300 missed? which is given in Z500 query.

Thanks & Regards  
Krishna Jalla

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [September 13, 2022, 7:30am UTC](https://discuss.elastic.co/t/es-version-range-comparision-is-not-working-as-expected-semantic-version-comparison/312904/8 "2022-09-13T07:30:31Z")

</div>

I am not familiar with the code, so will leave it to someone else to answer that.

---

<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:** [October 11, 2022, 7:31am UTC](https://discuss.elastic.co/t/es-version-range-comparision-is-not-working-as-expected-semantic-version-comparison/312904/9 "2022-10-11T07:31:31Z")

</div>

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