Elasticsearch phrase prefix query on multiple fields Elasticsearch phrase prefix query on multiple fields elasticsearch elasticsearch

Elasticsearch phrase prefix query on multiple fields


The text query that you are using has been deprecated (effectively renamed) a while ago in favour of the match query. The match query supports a single field, but you can use the multi_match query which supports the very same options and allows to search on multiple fields. Here is an example that should be helpful to you:

{    "query" : {        "multi_match" : {            "fields" : ["title", "subtitle"],            "query" : "trying out ela",            "type" : "phrase_prefix"        }    }}

You can achieve the same using the Java API like this:

QueryBuilders.multiMatchQuery("trying out ela", "title", "subtitle")    .type(MatchQueryBuilder.Type.PHRASE_PREFIX);