title: Elasticsearch.Net query using NEST and nested objects to retrieve documents
body: <p>I'm using Elasticsearch.Net and NEST in an applicationand having trouble accessing documents in an Elasticsearh index when searching based on nested object Ids. The data structure is invoice -> lineItems -> rowItems. I want to search based on these rowItems Id. The (simplified) mapping of the index is:</p>
  
  <pre><code>"invoice": {
      "properties": {
        "lineItems": {
          "properties": {
            "accountId": {
              "index": "not_analyzed",
              "type": "string"
            },
            "listItems": {
              "properties": {
                "itemName": {
                  "analyzer": "str_index_analyzer",
                  "term_vector": "with_positions_offsets",
                  "type": "string",
                  "fields": {
                    "raw": {
                      "analyzer": "str_search_analyzer",
                      "type": "string"
                    }
                  }
                },
                "listItemID": {
                  "index": "not_analyzed",
                  "type": "string"
                }
              }
            }
          }
        }
      }
  }
  </code></pre>
  
  <p>And when I do a sense search in chrome of one of the nested objects I can successfully retrieve it:</p>
  
  <pre><code>POST /_search
  {
    "query": {
      "bool": {
        "should": [
          {"match": {
              "lineItems.rowItems.rowItemID" : "23f2157f-eb21-400d-b3a1-a61cf1451262"            
          }} 
        ]
      }
    }
  }
  </code></pre>
  
  <p>Which returns the document type Invoice with all its details.</p>
  
  <p>I've been playing around with the code to do this using NEST but have failed so far. I have a list of rowItemIds and I want to get all invoice documents that have an exact match on those Ids. This is what I currently have:</p>
  
  <pre><code>            var result = Execute(client =&gt; client.Search&lt;Invoice&gt;(s =&gt; s
      .Aggregations(a =&gt; a
          .Nested("my_nested_agg", n =&gt; n
              .Path("lineItems")
              .Aggregations(aa =&gt; aa
                  .Filter("my_avg_agg", avg =&gt; avg
                      .Field(p =&gt; searchIds.Contains(p.LineItems.First().RowItems.First().TrackingItemID))
                  )
              )
          )
      )
  ));
  </code></pre>
  
  <p>Where searchIds is the list of rowItemIds I'm searching for. The above code is totally wrong and I'm not familiar with the syntax on how to do this. Any help would be greatly appreciated.</p>