I'm looking for a way to save a dotted version as string (e.g "1.2.23") in elastic and then use range query on this field. e.g
{
"query": {
"range": {
"version": {"gte": "1.2.3", "lt": "1.3"}
}
}
}
I have only 3 components (major, minor, build). I need to be able to determine that
- 1.20.3 > 1.2.3
- 1.02.4 > 1.2.3
- 1.3 > 1.2.3
I thought about the following approaches:
- Pad with zeros (e.g "1.2.3" -> "000001.000002.000003"). This assumes I know the max length of each component
- Split into 3 different integer fields (i.e "major", "minor", "build"). Writing queries for this seems to be a pain, but I'd be happy to get suggestions for this.
- Perhaps some sort of a custom analyser? I saw this: Elasticsearch analysis plugin for natural sort which might be a good start.
Any other ideas or recommendations?