Nest Client - Searching nested properties

(Bo Clifton) #1

I'm having a tough time finding information on how to search nested properties using the Nest client in C#.

I have email objects in an index with approximately this shape:
{

  subject: “This is a test”,
  content: “This is an email written as a test of the Elasticsearch system.  Thanks, Mr Tom Jones”,
  custodians: [
    {
      firstName: “Tom”,
      lastName: “Jones”,
      routeType: 0
    },
    {
      firstName: “Matthew”,
      lastName: “Billsley”,
      routeType: 1
    }
  ]
}

You should be able to see that there is an array in there called “custodians” which is a list of all the senders and recipients of the email. In the Fluent-style query builder in .Net I can build the query just fine when I’m using subject, content, and other “first tier” properties. But I may only want to include custodians who have the routeType = 0 in some queries. I can’t seem to find any guidance on how to accomplish this. Any ideas?

For instance, a query for the term “picnic” in the subject field would look like:

Client.SearchAsync(m => m
  .Query(q => q
    .Match(f => f
      .Field(msg => msg.Subject)
      .Query(“picnic”))));

What would the query to only get messages from the index with routeType = 0 and lastName = “Jones” be?

(system) closed #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.