Created
March 9, 2012 15:21
-
-
Save mtyaka/2006966 to your computer and use it in GitHub Desktop.
Case insensitive tags in ES
This file contains 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
# Add this to config/elasticsearch.yml file to register the custom analyzer: | |
# Register the custom 'lowercase_keyword' analyzer. It doesn't do anything else | |
# other than changing everything to lower case. | |
index.analysis.analyzer.lowercase_keyword.type: custom | |
index.analysis.analyzer.lowercase_keyword.tokenizer: keyword | |
index.analysis.analyzer.lowercase_keyword.filter: [lowercase] |
This file contains 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
# Map the 'tags' property to two fields: one that isn't analyzed, | |
# and one that is analyzed with the 'lowercase_keyword' analyzer. | |
curl -XPUT 'http://localhost:9200/myindex/images/_mapping' -d '{ | |
"images": { | |
"properties": { | |
"tags": { | |
"type": "multi_field", | |
"fields": { | |
"tags": { | |
"index": "not_analyzed", | |
"type": "string" | |
}, | |
"lowercased": { | |
"index": "analyzed", | |
"analyzer": "lowercase_keyword", | |
"type": "string" | |
} | |
} | |
} | |
} | |
} | |
}' | |
# Issue queries against the index. The search query must be manually lowercased. | |
curl -XPOST 'http://localhost:9200/myindex/images/_search?pretty=true' -d '{ | |
"query": { | |
"terms": { | |
"tags.lowercased": [ | |
"event:battle at the boardwalk" | |
] | |
} | |
}, | |
"facets": { | |
"tags": { | |
"terms": { | |
"field": "tags", | |
"size": "500", | |
"regex": "^team:.*" | |
} | |
} | |
} | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment