Skip to content

Instantly share code, notes, and snippets.

@carantunes
Last active August 17, 2020 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carantunes/d77adbfaaa2c1001061765e1cf6d0c28 to your computer and use it in GitHub Desktop.
Save carantunes/d77adbfaaa2c1001061765e1cf6d0c28 to your computer and use it in GitHub Desktop.
case and accent insensitive mapping and query in elasticsearch
PUT /my_index
{
"settings": {
"analysis": {
"analyzer": {
"case_accent_analyzer": {
"tokenizer": "standard",
"filter": [
"lowercase",
"asciifolding"
]
}
},
"normalizer": {
"case_accent_normalizer": {
"type": "custom",
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
},
"mappings": {
"properties": {
"text": {
"type": "text",
"analyzer": "case_accent_analyzer",
"fields": {
"keyword": {
"type": "keyword",
"normalizer": "case_accent_normalizer"
}
}
},
"keyword": {
"type": "keyword",
"normalizer": "case_accent_normalizer"
}
}
}
}
POST my_index/_doc/1
{ "text":"olá", "keyword": "chá"}
GET /my_index/_doc/1
GET /my_index/_search
{
"query": {
"query_string": {
"query": "keyword:cha AND text.keyword:olá"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment