Last active
May 11, 2018 20:40
-
-
Save EdgeCaseBerg/79abfc338326c18bfacb31b0767732fb to your computer and use it in GitHub Desktop.
Case Insensitive ElasticSearch Regular expressions
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
# Delete any old test index | |
DELETE example_copy | |
# Create index with appropriate mappings/settings | |
# Note that the pattern is meant to not match anything so that the entire field is taken as the "token" | |
PUT example_copy | |
{ | |
"settings": { | |
"analysis": { | |
"analyzer": { | |
"caseInsensitive": { | |
"type" : "pattern", | |
"pattern" : "abcdefghijklmnopqrstuvwxyzywx", | |
"filter" : ["lowercase"] | |
} | |
} | |
} | |
}, | |
"mappings": { | |
"example" : { | |
"properties": { | |
"original" : { | |
"type": "string", | |
"copy_to": ["copied", "unindex"] | |
}, | |
"copied" : { | |
"type": "string", | |
"index": "analyzed", | |
"analyzer": "caseInsensitive" | |
}, | |
"unindex" : { | |
"type": "string", | |
"index": "not_analyzed" | |
} | |
} | |
} | |
} | |
} | |
# Create document | |
POST /example_copy/example | |
{ | |
"original" : "Hello There FRiend" | |
} | |
# Will return document | |
POST /example_copy/_search | |
{ | |
"query": { | |
"regexp" : { | |
"original" : { | |
"value" : "t.*" | |
} | |
} | |
} | |
} | |
# Will return document | |
POST /example_copy/_search | |
{ | |
"query": { | |
"regexp" : { | |
"copied" : { | |
"value" : "h.*" | |
} | |
} | |
} | |
} | |
# Will return document because case sensitive unindex field. | |
POST /example_copy/_search | |
{ | |
"query": { | |
"regexp" : { | |
"unindex" : { | |
"value" : "H.*" | |
} | |
} | |
} | |
} | |
# Will NOT return document because the value in the field is 'h' not 'H' due to the lowercase filter | |
POST /example_copy/_search | |
{ | |
"query": { | |
"regexp" : { | |
"copied" : { | |
"value" : "H.*" | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment