WARNING: Version 5.x has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
Verbatim and Strict Query Usage
editVerbatim and Strict Query Usage
editVerbatim Query Usage
editAn individual query can be marked as verbatim in order take effect; a verbatim query will be serialized and sent in the request to Elasticsearch, bypassing NEST’s conditionless checks.
Fluent DSL example
editq .Bool(b => b .Must(qt => qt .Term(t => t .Verbatim() .Field(p => p.Description) .Value("") ), qt => qt .Term(t => t .Field(p => p.Name) .Value("foo") ) ) )
Object Initializer syntax example
editnew TermQuery { IsVerbatim = true, Field = "description", Value = "" } && new TermQuery { Field = "name", Value = "foo" }
Example json output.
{ "bool": { "must": [ { "term": { "description": { "value": "" } } }, { "term": { "name": { "value": "foo" } } } ] } }
A compound query can also be marked as verbatim, demonstrated here with a bool
query.
Fluent DSL example
editq .Bool(b => b .Verbatim() )
Object Initializer syntax example
editnew BoolQuery { IsVerbatim = true, }
Example json output.
{ "bool": {} }
A single verbatim query will be serialized as-is
Fluent DSL example
editq .Term(t => t .Verbatim() .Field(p => p.Description) .Value("") )
Object Initializer syntax example
editnew TermQuery { IsVerbatim = true, Field = "description", Value = "" }
Example json output.
{ "term": { "description": { "value": "" } } }
Leaf queries within a compound query marked as verbatim will also be serialized as-is
Fluent DSL example
editq .Bool(b => b .Filter(f => !f .Term(t => t .Verbatim() .Field(p => p.Name) .Value("") ) && f .Exists(e => e .Field(p => p.NumberOfCommits) ) ) )
Object Initializer syntax example
editnew BoolQuery { Filter = new QueryContainer[] { !new TermQuery { IsVerbatim = true, Field = "name", Value = "" } && new ExistsQuery { Field = "numberOfCommits" } } }
Example json output.
{ "bool": { "filter": [ { "bool": { "must": [ { "exists": { "field": "numberOfCommits" } } ], "must_not": [ { "term": { "name": { "value": "" } } } ] } } ] } }
Strict Query Usage
editA query can be marked as strict meaning that if it is determined to be conditionless, it will throw an
exception. The following example demonstrates this by trying to send an empty string as the value for
a term
query marked as strict