pavan sp
pavan sp

Reputation: 105

Match phrase query with multiple fields in elasticsearch using nest

I am trying to query using matchphrase but on multiple fields but my nest allows me to do it on only one field here's my code snippet

    var result = client.Search<document>(s => s
    .Analyzer("automplete")
    .Query(p => p
    .MatchPhrase(M => M
    .OnField("description")
    .Query(value))));

I have multiple fields in class documents and I want search on that fields too.

Please help me with this - thanks in advance!

Upvotes: 2

Views: 3725

Answers (1)

bittusarkar
bittusarkar

Reputation: 6357

match_phrase does not even support multiple fields. For using a match query over multiple fields, you need to use multi_match query.

var result = client.Search<document>(s => s
    .Analyzer("automplete")
    .Query(p => p
        .MultiMatch(m => m
            .OnFields(new[] { "description" /*, add other fields here */ })
            .Query(value)
            .Type(TextQueryType.Phrase))));

Upvotes: 4

Related Questions