I am trying to do a query against an index using the snowball analyzer. It appears to not be working correctly. If I type in “starbucks” it will return 0 results however if I type in “starbuck” it returns all data with “Starbucks” in the name.
I know that when doing a normal search you must explicitly specify the field in order for a search_analyzer to be utilized.
Is it strange that _mapping says I am using the snowball index_analyzer but doesn’t mention the snowball search_analyzer?
Mapping Snippet:
name: {
type: "string",
search_analyzer : "snowball",
index_analyzer : "snowball",
boost : 1
},
tags: {
type: "string",
search_analyzer : "snowball",
index_analyzer : "snowball",
boost : 4
}
Snippet from /businesses/business/_mapping
name: {type: "string",analyzer: "snowball"},
tags: {type: "string",boost: 4,analyzer: "snowball"}
Java Code to do my search:
val response = client.prepareSearch("businesses")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(termQuery("name", term))
.setFrom(0).setSize(100).setExplain(true)
.execute()
.actionGet();
The term specified in
termQueryis not analyzed and used as is. Since the wordStarbucksi s indexed as termstarbuckyou are able to get some results back. When you are searching for the termStarbucksthere is no such term in the index and you are not getting any results. I would recommend usingtextquery instead, which will perform analysis of your term.