user3704685
user3704685

Reputation: 23

Elastic Wild card search not working with space

I am trying to make search from elastic search index, using wildcard filter, it working properly till i use "space" in my search criteria.

Ex : if value in elastic index is "This is test value"

when i use search value : "This*" --> Working, fetching the value when i use search value : "This is*"--> not working, resulting in zero match

my code looks as follows

QueryBuilders.wildcardQuery(
ElasticSearchUtil.FIELDNAME, searchValue.toLowerCase())

how can i handle space and make my search successful?

regards UI

Upvotes: 2

Views: 3583

Answers (1)

imotov
imotov

Reputation: 30163

The wildcard query works only with a single token. What you are trying to do is to find one token followed by another token with the second token being specified by a prefix. This can be achieved by using match phrase prefix query. Your query would look like this:

QueryBuilders.matchPhrasePrefixQuery(ElasticSearchUtil.FIELDNAME, searchValue)

Please note that the searchValue shouldn't have "*" at the end.

Upvotes: 5

Related Questions