I'm indexing my query as follows:
client.Index(new PercolatedQuery
{
Id = "std_query",
Query = new QueryContainer(new MatchQuery
{
Field = Infer.Field<LogEntryModel>(entry => entry.Message),
Query = "just a text"
})
}, d => d.Index(EsIndex));
client.Refresh(EsIndex);
Now, how do I use the percolator capabilities of ES to match an incoming document with this query? To say the NEST documentation is lacking in this area would be a huge understatement. I tried using client.Percolate
call, but it's deprecated now and they advise to use the search api, but don't tell how to use it with percolator...
I'm using ES v5 and the same version of NEST lib.
There are plans to improve the documentation for 5.x once the GA release is out; I understand that documentation could be clearer in many places and any help in this area would be most appreciated :)
The documentation for the Percolate query is generated from the integration test for it. Pulling out all the pieces for an example here, using details from you other question. First, let's define the POCO models
We're going to fluently map all properties instead of using mapping attributes. The fluent mappings are the most powerful and can express all ways to map in Elasticsearch.
Now, create the connection settings and client to work with Elasticsearch.
We can specify the index name and type name to infer for our POCOs; that is, when NEST makes a request using
LogEntryModel
orPercolatedQuery
as the generic type parameter in a request (e.g. theT
in.Search<T>()
), it will use the inferred index name and type name if they are no specified on the request.Now, delete the index so that we can start from scratch
And create the index
The
Query
property on thePercolatedQuery
is mapped as apercolator
type. This is new in Elasticsearch 5.0. The mapping request looks likeNow, we're ready to index the query
With the query indexed, Let's percolate a document
The percolated query with id
"std_query"
comes back in thesearchResponse.Documents
This is an example of percolating a document instance. Percolation can also be run against already indexed documents