Elasticsearch phrase prefix query on multiple fields

前端 未结 1 1971
北海茫月
北海茫月 2020-12-30 02:06

I\'m new to ES and I\'m trying to build a query that would use phrase_prefix for multiple fields so I dont have to search more than once.

Here\'s what I\'ve got so f

相关标签:
1条回答
  • 2020-12-30 02:15

    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);
    
    0 讨论(0)
提交回复
热议问题