Kishan Sojitra Kishan Sojitra - 2 months ago 34
C# Question

How to add Terms into Terms Query (ElasticSearch NEST C#)?

I'm writing a

in NEST. I have created a
for it. Here is my code:

QueryContainer qc1 = new TermsQuery()
Field = "recordID",
Terms =

I want to add
array as Terms and it shows that terms only accept
. I have tried converting array to Enumbrable and it's not working.

I just want to know what kind of object Terms accept?

Thanks in advance.


Terms accepts an IEnumerable<object> so it can accept a collection of any objects :) The type to use will depend on the field that you are querying against.

Given the model

public class Document
    public int Property1 { get; set; }

To pass it a collection of int or any other type

var termQuery = new TermsQuery
    Field = Infer.Field<Document>(d => d.Property1),
    Terms = new object[] { 1, 3, 5 }