Last active
August 17, 2020 14:22
-
-
Save carantunes/d77adbfaaa2c1001061765e1cf6d0c28 to your computer and use it in GitHub Desktop.
case and accent insensitive mapping and query in elasticsearch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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