C# NEST conditional filter in SubList

Viewed 49

I have a problem about QueryContainerDescriptor function, I define the StudentDocument

public class StudentDocument {
    public int id {get;set;}
    public string studentname {get;set;}
    public string studentnumber {get;set;}
    public IEnumerable<book> favourbooks {get;set;}
}

public class book {
    public int id {get;set;}
    public string bookname {get;set;}
    public string AuthorName {get;set;}
}

I define filter as below code

var filters = new List<Func<QueryContainerDescriptor<StudentDocument>, QueryContainer>>();
 filters.Add(fq => fq.Terms(t => t.Field(f => f.studentnumber).Terms("1346282")));

var response = await client.SearchAsync<StudentDocument>(x => x.Query(q => q
     .Bool(bq => bq.Filter(filters))));

The elastic search return output will be :

{
  "total": 1,
  "results": [
    {
      "id": 1346282,
      "studentname": "Casey",
      "studentnumber" :"YT2021"
      "favourbooks": [
        {
             "id": 1,
             "bookname":"Three Little Pig",
             "AuthorName":"Steven Kellogg"
        },
        {
             "id": 2,
             "bookname":"Winnie The Pooh",
             "AuthorName":"A. A. Milne"
        }
      ]
    }
}

This part is work. But I don't know how to do filter to search into sub list E.g. add more filter where studentname.favourbooks =="Three Little Pig"

Can anyone advise this ?

Thank you

0 Answers
Related