- .NET Clients: other versions:
- Introduction
- Installation
- Breaking changes
- API Conventions
- Elasticsearch.Net - Low level client
- NEST - High level client
- Troubleshooting
- Search
- Query DSL
- Full text queries
- Term level queries
- Exists Query Usage
- Fuzzy Date Query Usage
- Fuzzy Numeric Query Usage
- Fuzzy Query Usage
- Ids Query Usage
- Prefix Query Usage
- Date Range Query Usage
- Long Range Query Usage
- Numeric Range Query Usage
- Term Range Query Usage
- Regexp Query Usage
- Term Query Usage
- Terms Set Query Usage
- Terms List Query Usage
- Terms Lookup Query Usage
- Terms Query Usage
- Wildcard Query Usage
- Compound queries
- Joining queries
- Geo queries
- Specialized queries
- Span queries
- NEST specific queries
- Aggregations
- Metric Aggregations
- Average Aggregation Usage
- Boxplot Aggregation Usage
- Cardinality Aggregation Usage
- Extended Stats Aggregation Usage
- Geo Bounds Aggregation Usage
- Geo Centroid Aggregation Usage
- Geo Line Aggregation Usage
- Max Aggregation Usage
- Median Absolute Deviation Aggregation Usage
- Min Aggregation Usage
- Percentile Ranks Aggregation Usage
- Percentiles Aggregation Usage
- Rate Aggregation Usage
- Scripted Metric Aggregation Usage
- Stats Aggregation Usage
- String Stats Aggregation Usage
- Sum Aggregation Usage
- T Test Aggregation Usage
- Top Hits Aggregation Usage
- Top Metrics Aggregation Usage
- Value Count Aggregation Usage
- Weighted Average Aggregation Usage
- Bucket Aggregations
- Adjacency Matrix Usage
- Auto Date Histogram Aggregation Usage
- Children Aggregation Usage
- Composite Aggregation Usage
- Date Histogram Aggregation Usage
- Date Range Aggregation Usage
- Diversified Sampler Aggregation Usage
- Filter Aggregation Usage
- Filters Aggregation Usage
- Geo Distance Aggregation Usage
- Geo Hash Grid Aggregation Usage
- Geo Tile Grid Aggregation Usage
- Global Aggregation Usage
- Histogram Aggregation Usage
- Ip Range Aggregation Usage
- Missing Aggregation Usage
- Multi Terms Aggregation Usage
- Nested Aggregation Usage
- Parent Aggregation Usage
- Range Aggregation Usage
- Rare Terms Aggregation Usage
- Reverse Nested Aggregation Usage
- Sampler Aggregation Usage
- Significant Terms Aggregation Usage
- Significant Text Aggregation Usage
- Terms Aggregation Usage
- Variable Width Histogram Usage
- Pipeline Aggregations
- Average Bucket Aggregation Usage
- Bucket Script Aggregation Usage
- Bucket Selector Aggregation Usage
- Bucket Sort Aggregation Usage
- Cumulative Cardinality Aggregation Usage
- Cumulative Sum Aggregation Usage
- Derivative Aggregation Usage
- Extended Stats Bucket Aggregation Usage
- Max Bucket Aggregation Usage
- Min Bucket Aggregation Usage
- Moving Average Ewma Aggregation Usage
- Moving Average Holt Linear Aggregation Usage
- Moving Average Holt Winters Aggregation Usage
- Moving Average Linear Aggregation Usage
- Moving Average Simple Aggregation Usage
- Moving Function Aggregation Usage
- Moving Percentiles Aggregation Usage
- Normalize Aggregation Usage
- Percentiles Bucket Aggregation Usage
- Serial Differencing Aggregation Usage
- Stats Bucket Aggregation Usage
- Sum Bucket Aggregation Usage
- Matrix Aggregations
- Metric Aggregations
Intervals Usage
editIntervals Usage
editAn intervals query allows fine-grained control over the order and proximity of matching terms. Matching rules are constructed from a small set of definitions, and the rules are then applied to terms from a particular field.
The definitions produce sequences of minimal intervals that span terms in a body of text. These intervals can be further combined and filtered by parent sources.
Be sure to read the Elasticsearch documentation on Intervals query
Fluent DSL example
editq .Intervals(c => c .Field(p => p.Description) .Name("named_query") .Boost(1.1) .AnyOf(any => any .Intervals(i => i .Match(m => m .Query("my favourite food") .MaxGaps(5) .Ordered() .Filter(f => f .Containing(co => co .Match(mm => mm .Query("kimchy") ) ) ) ) .AllOf(all => all .Intervals(ii => ii .Match(m => m .Query("hot water") ) .Match(m => m .Query("cold porridge") ) ) .Filter(f => f .Script(s => s .Source("interval.start > 0 && interval.end < 200") ) ) ) ) ) )
Object Initializer syntax example
editnew IntervalsQuery { Field = Field<Project>(p => p.Description), Name = "named_query", Boost = 1.1, AnyOf = new IntervalsAnyOf { Intervals = new IntervalsContainer[] { new IntervalsMatch { Query = "my favourite food", MaxGaps = 5, Ordered = true, Filter = new IntervalsFilter { Containing = new IntervalsMatch { Query = "kimchy" } } }, new IntervalsAllOf { Intervals = new IntervalsContainer[] { new IntervalsMatch { Query = "hot water", }, new IntervalsMatch { Query = "cold porridge", }, }, Filter = new IntervalsFilter { Script = new InlineScript("interval.start > 0 && interval.end < 200") } } } } }
Example json output.
{ "intervals": { "description": { "_name": "named_query", "boost": 1.1, "any_of": { "intervals": [ { "match": { "query": "my favourite food", "max_gaps": 5, "ordered": true, "filter": { "containing": { "match": { "query": "kimchy" } } } } }, { "all_of": { "intervals": [ { "match": { "query": "hot water" } }, { "match": { "query": "cold porridge" } } ], "filter": { "script": { "source": "interval.start > 0 && interval.end < 200" } } } } ] } } } }
Prefix and Wildcard rules
editPrefix and Wildcard rules can be used to search for intervals that contain terms starting with a prefix, or match a pattern, respectively.
Only available in Elasticsearch 7.3.0+
Fluent DSL example
editq .Intervals(c => c .Field(p => p.Description) .Name("named_query") .Boost(1.1) .AnyOf(any => any .Intervals(i => i .Wildcard(m => m .Pattern(IntervalsPrefix + "*") ) .Prefix(m => m .Prefix(IntervalsPrefix) ) ) ) )
Object Initializer syntax example
editnew IntervalsQuery { Field = Field<Project>(p => p.Description), Name = "named_query", Boost = 1.1, AnyOf = new IntervalsAnyOf { Intervals = new IntervalsContainer[] { new IntervalsWildcard { Pattern = IntervalsPrefix + "*" }, new IntervalsPrefix { Prefix = IntervalsPrefix } } } }
Example json output.
{ "intervals": { "description": { "_name": "named_query", "boost": 1.1, "any_of": { "intervals": [ { "wildcard": { "pattern": "lorem*" } }, { "prefix": { "prefix": "lorem" } } ] } } } }
Fuzzy rules
editFuzzy rules can be used to match terms that are similar to the provided term, within an edit distance defined by Fuzziness. If the fuzzy expansion matches more than 128 terms, Elasticsearch returns an error.
Only available in Elasticsearch 7.6.0+
Fluent DSL example
editq .Intervals(c => c .Field(p => p.Description) .Name("named_query") .Boost(1.1) .Fuzzy(m => m .Term(IntervalsFuzzy) .Fuzziness(Fuzziness.Auto) ) )
Object Initializer syntax example
editnew IntervalsQuery { Field = Field<Project>(p => p.Description), Name = "named_query", Boost = 1.1, Fuzzy = new IntervalsFuzzy { Term = IntervalsFuzzy, Fuzziness = Fuzziness.Auto } }
Example json output.
{ "intervals": { "description": { "_name": "named_query", "boost": 1.1, "fuzzy": { "term": "lorem", "fuzziness": "AUTO" } } } }
On this page