Hello, i am using NEST to query Elastic from my C# app and was wondering if there was a way to pass in a list of string to the term query?
I currently have something similar with SOLR (SolrQueryInList("FIELDNAME", array of terms)
I am currently doing this
var result = client.Search(s => s
.Size(0)
.Query(q => q
.Term(p => p.createdby, "USERID1") || q.Term(p => p.createdby, "USERID2") || q.Term(p => p.createdby, "USERID3"))
I would rather pass in a list of users since i have quite a few to pass into my query.
var result = client.Search<Document>(s => s
.Query(q => q
.Terms(t => t
.Field(p => p.createdby)
.Terms("USERID1", "USERID2", "USERID3")
)
)
);
or
var result = client.Search<Document>(s => s
.Query(q => q
.Terms(t => t
.Field(p => p.createdby)
.Terms<string>(new List<string>{ "USERID1", "USERID2", "USERID3" })
)
)
);
If passing some kind of IEnumerable<T> to Terms<T>(), I would recommend explicitly specifying the type of T as I have done above with string in the second example; In NEST 2.x prior to 2.1.0, not specifying the generic parameter type meant that the params T[] overload of Terms() was incorrectly called.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.