Reputation: 4853
I'm trying to do an Elastic search for names that are inside brackets. I'm working with a database of names, and some of the names include maiden names within the first name field. Maiden names are indicated with brackets, like "Samantha [Murray]". My clients want our 'exact search' feature to work so that if you search for "Murray" you only get results with firstname Murray, not including maiden names; but if you search for "[Murray]", you get maiden names but NOT firstname = Murray, i.e. search for "Murray" >> "Murray Smith" but not "Samantha [Murray] Jones", search for "[Murray]" >> vice versa.
My problem so far is that elastic search seems to be ignoring the brackets entirely. Here is my query...
{
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"query_string": {
"default_field" : "first_name",
"query" : "\\[Murray\\]"
}
}
]
}
}
}
}
}
but I get the same results that I do for "query" : "Murray" with no brackets at all. I tried a regexp but the results were even worse, the names I got weren't even close to "Murray" (I got things like "Rogers").
Is this type of request possible in Elastic? If so, what do I need to change?
Upvotes: 2
Views: 3877
Reputation: 2147
Get familiar with analyzers - http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/analysis-analyzers.html
If you are using the defaults your analyzer is probably stripping down the brackets. You need to define an analyzer that doesn't remove brackets if you want to be able to search by it.
Upvotes: 2