- .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
Percolate Query Usage
editPercolate Query Usage
editThe percolate query can be used to match queries stored in an index. The percolate query itself contains the document that will be used as query to match with the stored queries.
In order for the percolate query to work, the index in which your stored queries reside must contain a mapping for documents that you wish to percolate, so that they are parsed correctly at query time.
See the Elasticsearch documentation on percolate query for more details.
In this example, we have a document stored with a query
field that is mapped as a percolator
type. This field
contains a match
query.
Fluent DSL example
editq .Percolate(p => p .Document(Project.Instance) .Field(f => f.Query) )
Object Initializer syntax example
editnew PercolateQuery { Document = Project.Instance, Field = Infer.Field<ProjectPercolation>(f => f.Query) }
Example json output.
{ "percolate": { "document": { "name": "Koch, Collier and Mohr", "state": "BellyUp", "startedOn": "2015-01-01T00:00:00", "lastActivity": "0001-01-01T00:00:00", "leadDeveloper": { "gender": "Male", "id": 0, "firstName": "Martijn", "lastName": "Laarman" }, "location": { "lat": 42.1523, "lon": -80.321 } }, "field": "query" } }
Handling Responses
editresponse.Total.Should().BeGreaterThan(0); response.Hits.Should().NotBeNull(); response.Hits.Count().Should().BeGreaterThan(0); var match = response.Documents.First(); match.Id.Should().Be(PercolatorId); ((IQueryContainer)match.Query).Match.Should().NotBeNull();
Percolate an existing document
editInstead of specifying the source of the document being percolated, the source can also be retrieved from an already stored document. The percolate query will then internally execute a get request to fetch that document.
The required fields to percolate an existing document are:
-
index
in which the document resides -
type
of the document -
field
that contains the query -
id
of the document -
document_type
type / mapping of the document
See the Elasticsearch documentation on percolate query for more details.
Fluent DSL example
editq .Percolate(p => p .Index<Project>() .Id(Project.Instance.Name) .Routing(Project.Instance.Name) .Field(f => f.Query) )
Object Initializer syntax example
editnew PercolateQuery { Index = IndexName.From<Project>(), Id = Project.Instance.Name, Routing = Project.Instance.Name, Field = Infer.Field<ProjectPercolation>(f => f.Query) }
Example json output.
{ "percolate": { "type": "doc", "index": "project", "id": "Durgan LLC", "routing": "Durgan LLC", "field": "query" } }
Handling Responses
editresponse.Total.Should().BeGreaterThan(0); response.Hits.Should().NotBeNull(); response.Hits.Count().Should().BeGreaterThan(0); var match = response.Documents.First(); match.Id.Should().Be(PercolatorId); ((IQueryContainer)match.Query).Match.Should().NotBeNull();
Percolate multiple documents
editThe percolate query can match multiple documents simultaneously with the indexed percolator queries. Percolating multiple documents in a single request can improve performance as queries only need to be parsed and matched once instead of multiple times.
See the Elasticsearch documentation on percolate query for more details.
Fluent DSL example
editq .Percolate(p => p .Documents(Project.Instance, Project.Instance, Project.Instance) .Field(f => f.Query) )
Object Initializer syntax example
editnew PercolateQuery { Documents = new[] { Project.Instance, Project.Instance, Project.Instance }, Field = Infer.Field<ProjectPercolation>(f => f.Query) }
Example json output.
{ "percolate": { "documents": [ { "name": "Koch, Collier and Mohr", "state": "BellyUp", "startedOn": "2015-01-01T00:00:00", "lastActivity": "0001-01-01T00:00:00", "leadDeveloper": { "gender": "Male", "id": 0, "firstName": "Martijn", "lastName": "Laarman" }, "location": { "lat": 42.1523, "lon": -80.321 } }, { "name": "Koch, Collier and Mohr", "state": "BellyUp", "startedOn": "2015-01-01T00:00:00", "lastActivity": "0001-01-01T00:00:00", "leadDeveloper": { "gender": "Male", "id": 0, "firstName": "Martijn", "lastName": "Laarman" }, "location": { "lat": 42.1523, "lon": -80.321 } }, { "name": "Koch, Collier and Mohr", "state": "BellyUp", "startedOn": "2015-01-01T00:00:00", "lastActivity": "0001-01-01T00:00:00", "leadDeveloper": { "gender": "Male", "id": 0, "firstName": "Martijn", "lastName": "Laarman" }, "location": { "lat": 42.1523, "lon": -80.321 } } ], "field": "query" } }
Handling Responses
editresponse.Total.Should().Be(1); response.Hits.Should().NotBeNull(); response.Hits.Count.Should().Be(1); response.Fields.Count.Should().Be(1); var field = response.Fields.ElementAt(0); var values = field.ValuesOf<int>("_percolator_document_slot"); values.Should().Contain(new[] { 0, 1, 2 }); var match = response.Documents.First(); match.Id.Should().Be(PercolatorId); ((IQueryContainer)match.Query).Match.Should().NotBeNull();
On this page