ElasticSearch: compare dotted version strings -


i'm looking way save dotted version string (e.g "1.2.23") in elastic , use range query on field. e.g

{  "query": {    "range": {     "version": {"gte": "1.2.3", "lt": "1.3"}    }   } } 

i have 3 components (major, minor, build). need able determine

  • 1.20.3 > 1.2.3
  • 1.02.4 > 1.2.3
  • 1.3 > 1.2.3

i thought following approaches:

  1. pad zeros (e.g "1.2.3" -> "000001.000002.000003"). assumes know max length of each component
  2. split 3 different integer fields (i.e "major", "minor", "build"). writing queries seems pain, i'd happy suggestions this.
  3. perhaps sort of custom analyser? saw this: elasticsearch analysis plugin natural sort might start.

any other ideas or recommendations?

if have latitude in indexing code massage semantic versions else, suggest transform each version unique integer , it's easy compare numbers single range query.

the algorithm simple:

  1. you split version on dots: 1.2.34 => 1, 2, 34
  2. you multiply major version 1000000: 1 => 1000000
  3. you multiply minor version 1000: 2 => 2000
  4. you sum 3 numbers up: 1000000 + 2000 + 34 => 1002034
  5. you store resulting number es documents , use compare versions in range queries

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -