Term Query Usageedit

Fluent DSL exampleedit

q
.Term(c => c
    .Name("named_query")
    .Boost(1.1)
    .Field(p => p.Description)
    .Value("project description")
)

Object Initializer syntax exampleedit

new TermQuery
{
    Name = "named_query",
    Boost = 1.1,
    Field = "description",
    Value = "project description"
}

Example json output.

{
  "term": {
    "description": {
      "_name": "named_query",
      "boost": 1.1,
      "value": "project description"
    }
  }
}

Verbatim term queryedit

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

Fluent DSL exampleedit

q
.Term(c => c
    .Verbatim()
    .Field(p => p.Description)
    .Value(string.Empty)
)

Object Initializer syntax exampleedit

new TermQuery
{
    IsVerbatim = true,
    Field = "description",
    Value = "",
}

Example json output.

{
  "term": {
    "description": {
      "value": ""
    }
  }
}