Term Query Usage

edit

Fluent DSL example

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

Object Initializer syntax example

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

edit

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 example

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

Object Initializer syntax example

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

Example json output.

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