user1578872
user1578872

Reputation: 9088

Elastic Search - Exact phrase search with wildcards

I am looking for help on exact phrase search with wild card.

QueryBuilders.multiMatchQuery("Java Se", "title", "subtitle")
    .type(MatchQueryBuilder.Type.PHRASE_PREFIX);

The above query, returns the following results.

1) Java Search 2) Elastic Java Search

Trailing wildcard works.

But, When i search like the below query,

QueryBuilders.multiMatchQuery("ava Se", "title", "subtitle")
    .type(MatchQueryBuilder.Type.PHRASE_PREFIX);

It does not return anything as nothing matches exactly "ava Se". I was expecting the same result as above.

Leading wildcard does not work. Is there anyway to achieve this?

Thanks, Baskar.S

Upvotes: 0

Views: 1334

Answers (2)

KLaz
KLaz

Reputation: 782

If you have a look at the javadoc for "Type.PHRASE_PREFIX" you will see that only the last term in the string is used as a prefix, thus only "Se" in your case.

I tried this query in my index and it worked: .setQuery(QueryBuilders.matchQuery("body", "(.*?)ing the").type(MatchQueryBuilder.Type.PHRASE_PREFIX))

It returned documents that contain phrases like "We are strengthening the proposals..", "By using the.."

Upvotes: 1

Vineeth Mohan
Vineeth Mohan

Reputation: 19283

You need to use nGram analyzer or even edgeNGram would be a better idea. Once you have done that , your index might be a bit heavy but affix search will work fine without wild cards.

Upvotes: 0

Related Questions