I'm trying to refactor our old search into elastic search and I'm trying to convert this expression into elastic search query.
AddQuery(q => q.InvoiceItem.Any(p => p.ItemId == itemId));
I have a document Invoice
that has a Field which is a list InvoiceItems
and I need to query all Invoices
that has a certain InvoiceItem
in their InvoiceItems
field.
Is it even possible in NEST?
CodePudding user response:
Finally solved it. I was able to achieve it using this syntax
AddQuery(m => m.Term(q => q.InvoiceItems.FirstOrDefault().ItemId,
int.Parse(search.SearchValue)));
Note: AddQuery
is just a helper function I made. Just focus on the expression for the answer.