- .NET Clients: other versions:
- Introduction
- 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
- Numeric Range Query Usage
- Term Range Query Usage
- Regexp Query Usage
- Term Query Usage
- Terms List Query Usage
- Terms Lookup Query Usage
- Terms Query Usage
- Type Query Usage
- Wildcard Query Usage
- Compound queries
- Joining queries
- Geo queries
- Geo Bounding Box Query Usage
- Geo Distance Query Usage
- Geo Distance Range Query Usage
- Geo Hash Cell Query Usage
- Geo Polygon Query Usage
- Geo Shape Circle Query Usage
- Geo Shape Envelope Query Usage
- Geo Shape Geometry Collection Query Usage
- Geo Shape Indexed Shape Query Usage
- Geo Shape Line String Query Usage
- Geo Shape Multi Line String Query Usage
- Geo Shape Multi Point Query Usage
- Geo Shape Multi Polygon Query Usage
- Geo Shape Point Query Usage
- Geo Shape Polygon Query Usage
- Specialized queries
- Span queries
- NEST specific queries
- Aggregations
- Metric Aggregations
- Average Aggregation Usage
- Cardinality Aggregation Usage
- Extended Stats Aggregation Usage
- Geo Bounds Aggregation Usage
- Geo Centroid Aggregation Usage
- Max Aggregation Usage
- Min Aggregation Usage
- Percentile Ranks Aggregation Usage
- Percentiles Aggregation Usage
- Scripted Metric Aggregation Usage
- Stats Aggregation Usage
- Sum Aggregation Usage
- Top Hits Aggregation Usage
- Value Count Aggregation Usage
- Bucket Aggregations
- Adjacency Matrix Usage
- Children Aggregation Usage
- Date Histogram Aggregation Usage
- Date Range Aggregation Usage
- Filter Aggregation Usage
- Filters Aggregation Usage
- Geo Distance Aggregation Usage
- Geo Hash Grid Aggregation Usage
- Global Aggregation Usage
- Histogram Aggregation Usage
- Ip Range Aggregation Usage
- Missing Aggregation Usage
- Nested Aggregation Usage
- Range Aggregation Usage
- Reverse Nested Aggregation Usage
- Sampler Aggregation Usage
- Significant Terms Aggregation Usage
- Terms Aggregation Usage
- Pipeline Aggregations
- Average Bucket Aggregation Usage
- Bucket Script Aggregation Usage
- Bucket Selector 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
- Percentiles Bucket Aggregation Usage
- Serial Differencing Aggregation Usage
- Stats Bucket Aggregation Usage
- Sum Bucket Aggregation Usage
- Matrix Aggregations
- Metric Aggregations
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.
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 .DocumentType(typeof(Project)) .Document(Project.Instance) .Field(f => f.Query) )
Object Initializer syntax example
editnew PercolateQuery { DocumentType = typeof(Project), Document = Project.Instance, Field = Infer.Field<PercolatedQuery>(f => f.Query) }
Example json output.
{ "percolate": { "document_type": "project", "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
editObject Initializer syntax example
editnew PercolateQuery { Type = typeof(Project), Index = IndexName.From<Project>(), Id = Project.Instance.Name, DocumentType = typeof(Project), Field = Infer.Field<PercolatedQuery>(f => f.Query) }
Example json output.
{ "percolate": { "type": "project", "index": "project", "id": "Durgan LLC", "document_type": "project", "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();
On this page