Kishan Sojitra Kishan Sojitra - 9 days ago 6
C# Question

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

I'm writing a

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

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


I want to add
int
array as Terms and it shows that terms only accept
IEnumerable<object>
. 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.

Answer

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 }
};