Terms Query Usageedit

Filters documents that have fields that match any of the provided terms (not analyzed).

Be sure to read the Elasticsearch documentation on Terms query for more information.

Fluent DSL exampleedit

q
.Terms(c => c
    .Name("named_query")
    .Boost(1.1)
    .Field(p => p.Description)
    .Terms("term1", "term2")
)

Object Initializer syntax exampleedit

new TermsQuery
{
    Name = "named_query",
    Boost = 1.1,
    Field = "description",
    Terms = ExpectedTerms,
}

Example json output. 

{
  "terms": {
    "_name": "named_query",
    "boost": 1.1,
    "description": [
      "term1",
      "term2"
    ]
  }
}

Single term Terms Queryedit

Fluent DSL exampleedit

q
.Terms(c => c
    .Name("named_query")
    .Boost(1.1)
    .Field(p => p.Description)
    .Terms("term1")
)

Verbatim terms queryedit

By default an empty terms array is conditionless so will be rewritten. Sometimes sending an empty an empty array to mean match nothing makes sense. You can either use the ConditionlessQuery construct from NEST to provide a fallback or make the query verbatim as followed:

Object Initializer syntax exampleedit

new TermsQuery
{
    IsVerbatim = true,
    Field = "description",
    Terms = new string[] {},
}

Example json output. 

{
  "terms": {
    "description": []
  }
}

Fluent DSL exampleedit

q
.Terms(c => c
    .Verbatim()
    .Field(p => p.Description)
    .Terms(new string[] {})
)