I seem to be having a problem getting an exact phrase match to work if
it has a space in it.
I am using a multi-map field defined as:
VendorName: {
type: multi_field
fields: {
VendorName: {
type: string
}
exact: {
include_in_all: false
analyzer: exact_match
type: string
}
}
The "exact_match" analyzer is defined as:
index.analysis.analyzer.exact_match.type: custom
index.analysis.analyzer.exact_match.filter: lowercase
index.analysis.analyzer.exact_match.tokenizer: keyword
I am doing this because this needs to be case insensitive.
I have double checked this analyzer with:
curl -XGET 'localhost:9200/test/_analyze?analyzer=exact_match' -d
'This-is a test'
And the response is:
{"tokens":[{"token":"this-is a test","start_offset":0,"end_offset":
14,"type":"word","position":1}]}'
which is what I expect.
I am building the query like this:
String exactString = "\"this-is a\"";
QueryStringQueryBuilder exactQuery =
QueryBuilders.queryString(exactString)
.defaultOperator(Operator.AND);
exactQuery.field("VendorName.exact");
filter = FilterBuilders.queryFilter(exactQuery);
AndFilterBuilder filters = new AndFilterBuilder();
filter.add(filter);
QueryBuilders.constantScoreQuery(filters);
I am building the And filters this way, because we can have rather
complex searching, however, in this case, even just this one entry
still doesn't work.
I have tried autoGeneratePhraseQueries() but that doesn't seem to do
anything, so I am adding the "" myself.
The search performs flawlessly for any phrase I use, as long as it
doesn't include a space. For instance, a "this-is" search works fine.
I have tried many different combinations of options, and I do believe
this current configuration should work.
I am using version 0.19.4 in this test.
Thanks for your help,
Tom