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:
"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"
}
}
}
}
}
}
}
And when I do a sense search in chrome of one of the nested objects I can successfully retrieve it:
POST /_search
{
"query": {
"bool": {
"should": [
{"match": {
"lineItems.rowItems.rowItemID" : "23f2157f-eb21-400d-b3a1-a61cf1451262"
}}
]
}
}
}
Which returns the document type Invoice with all its details.
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:
var result = Execute(client => client.Search<Invoice>(s => s
.Aggregations(a => a
.Nested("my_nested_agg", n => n
.Path("lineItems")
.Aggregations(aa => aa
.Filter("my_avg_agg", avg => avg
.Field(p => searchIds.Contains(p.LineItems.First().RowItems.First().TrackingItemID))
)
)
)
)
));
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.