I’m really new to elasticsearch and NEST, so sorry for the basic question.
I’m trying to find out how i can search for all documents that have a match in a collection property.
My elastic document object looks something like this :
[ElasticType(Name="my_document")]
public class MyDocument
{
public long Id { get; set; }
public long[] TagIds { get; set; }
}
I would like to know how i search for documents that their TagIds property have a certain number in them.
I would like to do something like this :
elasticClient.Search<MyDocument>(x =>
x.Query(s => s.Terms(z => z.TagIds.Contains(searchVal))));
Found it, the answer is really simple, I just didn’t fully understand the documentation when i read it.
The query I was looking for is :
Note : I am using
Term()and notTerms(). The second parameter is a string of the tagId i’m looking for inside the collection. (This could be an int as well, in my case it’s a long, so i search by strings)Leaving this question up so it might help someone else sometime… 🙂