Skip to content

UXScripts/elasticsearch-analysis-naturalsort

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Settings

index:
  analysis:
      analyzer:
          naturalsort:
              tokenizer: keyword
              filter: naturalsort

Mappings

{ 
  "type1" : { 
    "properties" : { 
         "points" : { 
            "type" : "multi_field", 
            "fields" : { 
                "points" : { "type" : "string" }, 
                "sort" : { "type" : "string", "analyzer" : "naturalsort" } 
            } 
         } 
     } 
  } 
}

Search

{
   "fields" : "points",
   "query": {
       "match_all" : {}
    },
    "sort" : { 
            "points.sort" : {
                 "order" : "asc"
            }
    }       
}

Response

{
  "took" : 54,
  "timed_out" : false,
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "failed" : 0
  },
  "hits" : {
    "total" : 3,
    "max_score" : null,
    "hits" : [ {
      "_index" : "test",
      "_type" : "type1",
      "_id" : "Ono1C2F7SdWBPL6QRAGA6Q",
      "_score" : null,
      "fields" : {
        "points" : "Bob: 2 points"
      },
      "sort" : [ "*\u0018䀊䀀。ᰁက挀㄀ᜀఠٰ̰\u0000\u0002\u0001\u0000䀀‎瀀ࠀЁ渀Ā�@ \u0010\b\u0000\u0004\u0001\u0000䀀 ကࠀЀȀĀ�@ \u0001" ]
    }, {
      "_index" : "test",
      "_type" : "type1",
      "_id" : "J5EornIuRKCy7_G084eyoQ",
      "_score" : null,
      "fields" : {
        "points" : "Bob: 3 points"
      },
      "sort" : [ "*\u0018䀊䀀。ᰁሀ挀㄀ᜀఠٰ̰\u0000\u0002\u0001\u0000䀀‎瀀ࠀЁ渀Ā�@ \u0010\b\u0000\u0004\u0001\u0000䀀 ကࠀЀȀĀ�@ \u0001" ]
    }, {
      "_index" : "test",
      "_type" : "type1",
      "_id" : "yHWy94jPTHqULtgSZvvysw",
      "_score" : null,
      "fields" : {
        "points" : "Bob: 10 points"
      },
      "sort" : [ "*\u0018䀊䀀。 ฀䘀ㆀᢀ஀̸ؐƘ\u0000\u0001\u0000䀀 ဇ㠀ЀȀĀ㮀@ \u0010\b\u0004\u0002\u0000\u0001\u0000 ကࠀЀȀĀ�@ \u0010\b\u0004\u0001" ]
    } ]
  }
}

About

Adding a natural sort key to Elasticsearch

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published