Home > OS >  Application version comparison with Elasticsearch
Application version comparison with Elasticsearch

Time:10-20

I have an elasticsearch index that contains application documents. Each document has application version and some other fields:

version: 2.3.4, name: Spotify

version: 1.2.3, name: Sudoku

How to apply GT(greater than) search by version or customize it in this case? If applications have 1.2.3 and 1.3.2 versions - it works fine using standard queries (GT 1 will return both documents), but in case of 1.2.3 and 2.1.3 ES returns only 1.2.3 version of the application.

Query:

"bool" : {
                  "should" : [
                    {
                      "range" : {
                        "application_version" : {
                          "from" : "1.2.3",
                          "to" : null,
                          "include_lower" : false,
                          "include_upper" : true,
                          "boost" : 1.0
                        }
                      }
                    }
                  ]

application_version type: keyword

CodePudding user response:

I've been researching and I believe the best option for you is to change the type of application_version to Version field type.

The version field type is a specialization of the keyword field for handling software version values and to support specialized precedence rules for them. Precedence is defined following the rules outlined by Semantic Versioning, which for example means that major, minor and patch version parts are sorted numerically (i.e. "2.1.0" < "2.4.1" < "2.11.2") and pre-release versions are sorted before release versions (i.e. "1.0.0-alpha" < "1.0.0").

  • Related