Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build multi match query with type set to "phrase_prefix" using Elastic Java Api instead of pure REST

According to the documentation of multi match query (https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html) it is possible to search multi properties by prefix. All you must do is to set parameter "type" to "phrase_prefix". Unfortunately I cannot find that option in Elastic Java Api (https://www.elastic.co/guide/en/elasticsearch/client/java-api/1.6/multimatch.html). I tried something like:

QueryBuilder builder = QueryBuilders
    .multiMatchQuery("query", "property1", "property2");

but cannot find where to set "type" parameter. I know pure rest is the solution but I'm limited to java api.

I'm using version 5.2.2 of org.elasticsearch.client:transport.

like image 328
Wojciech Wirzbicki Avatar asked Mar 28 '17 07:03

Wojciech Wirzbicki


1 Answers

You have to add .type(MatchQueryBuilder.Type.PHRASE_PREFIX) to your builder.

Example:

QueryBuilder builder = QueryBuilders
    .multiMatchQuery("query", "property1", "property2")
    .type(MatchQuery.Type.PHRASE_PREFIX)
like image 115
Roma Khomyshyn Avatar answered Oct 31 '22 23:10

Roma Khomyshyn