Terms Query Usage

edit

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 example

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

Object Initializer syntax example

edit
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 Query

edit

Fluent DSL example

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

Verbatim terms query

edit

By default an empty terms array is conditionless so will be rewritten. Sometimes sending 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 example

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

Example json output.

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

Fluent DSL example

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