When testing the query the results are correct when I use one or more string values containing a single word, such as “Vale”. However, when I use a string containing a whitespace such as “St. Paul” instead of filtering results I get ALL items from all counties returned. It’s like it’s either ignoring it or doing some kind of fuzzy matching even though it is a filter and no fuzzy search is set.
Can anyone provide any insight as to why that is the case and how I may resolve it?
I managed to resolve the issue. It was down to the search analyzer. By default I was using the Standard analyzer. This analyzer “divides text into terms based on word boundaries”.
So when it saw a word boundary such as “St. Paul” it was breaking the words up into separate “tokens”: “St.” and “Paul”. As I have a few area names starting with “St.” it was returning all of those that matched. This explains why it was working with single-word terms but not multi-word.
To resolve the issue I set the Keyword analyzer only on the field in question. The Keyword analyzer “accepts a string or array of strings as a parameter and indexes them as single terms. Only exact matches on the field are returned.” This is the behaviour I needed as I was passing the exact phrase.
With the Keyword analyzer applied to the field the search returned the correct results.