MKasprzyk
MKasprzyk

Reputation: 499

How to make double nested query in C# Nest

I've got problem with nested query.

My model looks like that:

public class Car
{
    public int Age {get; set;}  
    public List<User> Users {get; set;}

}

public class User
{
    public List<string> Names {get; set;}
    public List<string> Surnames {get; set;}

}

It can't be modify.

and my object looks like:

{
  "age": 12,
  "users": [
    {
      "names": [
        "Adam",
        "Bob"
      ],
      "surnames": [
        "xyz",
        "abc"
      ]
    }
  ]
}

How should look code to find car whose user is Bob? I know that example is not very good, but it shows central point of my problem.

Upvotes: 1

Views: 183

Answers (1)

MKasprzyk
MKasprzyk

Reputation: 499

var result1 = await _ec.SearchAsync<Car>(s => s.Query(q => q.Term(t => t.Field("users.names").Value("Bob"))));

Upvotes: 1

Related Questions