0

I am trying to convert the below elastic search DSL to a NEST query, I am using version 5.2 of elasticsearch

GET articles/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "FIY",
            "fields": [
              "title"
            ]
          }
        },
        {
          "nested": {
            "path": "tags",
            "query": {
              "terms": {
                "tags.tagName": [
                  "competition"
                ]
              }
            }
          }
        }
      ]
    }
  }
}

So far I have got the below, I know that the filter part shouldn't be in there, but I cant seem to add the Nested part without it

var result = client.Search<Article>(x => x
                .Query(q => q
                    .Bool(b => b
                        .Must(m => m 
                            .MultiMatch(mp => mp
                                .Query(query)
                                    .Fields(f => f
                                        .Fields(f1 => f1.Title, f2 => f2.Content, f3 => f3.Tags))))

                        .Filter(f => f
                            .Nested(n => n
                                .Path("tags")
                                .Query(q1 => q1
                                    .Terms(t1 => t1.Field(f2 => f2.Tags).Terms(tags))
                                         ))))));

1 Answer 1

2

You dont need to use Filter.Just add Nested into Must Query

  var result = client.Search<Article>(x => x
                .Query(q => q
                    .Bool(b => b
                        .Must(m => m 
                            .MultiMatch(mp => mp
                                .Query(query)
                                    .Fields(f => f
                                        .Fields(f1 => f1.Title, f2 => f2.Content, f3 => f3.Tags)),                    
                           m=> m.Nested(n => n
                                .Path("tags")
                                .Query(q1 => q1
                                    .Terms(t1 => t1.Field(f2 => f2.Tags).Terms(tags))
                                         )))));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.