Skip to content

Instantly share code, notes, and snippets.

@jprante
Last active August 18, 2021 08:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jprante/6068637 to your computer and use it in GitHub Desktop.
Save jprante/6068637 to your computer and use it in GitHub Desktop.
Norwegian Bokmål sort with Elasticsearch
# Norwegian Bokmål sort with ICU
# ES 0.90.2
# ./bin/plugin --install elasticsearch/elasticsearch-analysis-icu/1.10.0
curl -XDELETE 'localhost:9200/test'
curl -XPUT 'localhost:9200/test' -d '
{
"settings" : {
"index" : {
"analysis" : {
"filter" : {
"bokmal": {
"type" : "icu_collation",
"language" : "nb"
}
},
"analyzer" : {
"bokmalAnalyzer" : {
"type" : "custom",
"tokenizer" : "keyword",
"filter" : "bokmal"
}
}
}
}
},
"mappings" : {
"_default_": {
"properties" : {
"name" : {
"type" : "string",
"analyzer" : "bokmalAnalyzer"
}
}
}
}
}
'
curl -XPUT 'localhost:9200/test/data/1' -d '
{
"name" : "åges plateselskap as"
}
'
curl -XPUT 'localhost:9200/test/data/2' -d '
{
"name" : "ølen fiskelag"
}
'
curl -XPUT 'localhost:9200/test/data/3' -d '
{
"name" : "æ vil ha dæ"
}
'
curl -XPUT 'localhost:9200/test/data/4' -d '
{
"name" : "yara international"
}
'
curl -XGET 'localhost:9200/test/_refresh'
# without sort
curl -XGET 'localhost:9200/test/data/_search?pretty' -d '
{
"query" : {
"match_all": {
}
}
}'
# with sort
curl -XGET 'localhost:9200/test/data/_search?pretty' -d '
{
"query" : {
"match_all": {
}
},
"sort" : {
"name" : {
"order" : "desc"
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment