0

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

user1578872
  • 7,808
  • 29
  • 108
  • 206

2 Answers2

1

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.."

Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177
KLaz
  • 446
  • 3
  • 11
0

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.

Vineeth Mohan
  • 18,633
  • 8
  • 63
  • 77
  • It works fine in the following case without using nGram. QueryBuilder queryBuilder = boolQuery().should( queryString("Mike Mat").analyzeWildcard(true) .field("firstName", 2.0f).field("lastName").field("title") .field("location").field("industry").field("email")); – user1578872 Apr 10 '15 at 12:12
  • Also, it works for trailing wild card, but not working for leading wildcard. – user1578872 Apr 10 '15 at 12:19