Is there a way to call Template Query using NEST? Is there any examples?
3 Answers
The search template endpoint isn't mapped in NEST yet, and poses a bit of a challenge since it's very different to how queries are normally constructed. We're actually working on this now (in this branch) and are hoping to get this functionality in the upcoming 1.1 release. Here's a link to the original issue for tracking purposes.
EDIT: Forgot to mention, the endpoint is available on the low-level Elasticsearch.Net client, which you can access via ElasticClient
:
var client = new ElasticClient(...);
client.Raw.SearchTemplate(...);

- 3,315
- 1
- 20
- 17
-
I knew low-level elasticsearch.net provided this but was curious about on the NEST side. Thanks bunch for your confirmation. – M Kim Sep 05 '14 at 20:23
The search template endpoint has been mapped in NEST 2.x.
There is a general example about templating here: https://www.elastic.co/guide/en/elasticsearch/client/net-api/2.x/template-query-usage.html
Here is some information about how inline templates can be used in a phrase suggestion with the collate option: https://www.elastic.co/guide/en/elasticsearch/client/net-api/2.x/suggest-usage.html
Here is an issue on GitHub I posted with some information on how to save templates to Elastic: https://github.com/elastic/elasticsearch-net/issues/2176
Here's a general example of how to use NEST:
var templateRequest= new PutSearchTemplateDescriptor(new Id("my_template"));
templateRequest.Template("{\"multi_match\":{\"query\":{\"query\":\"{{suggestion}}\",\"fields\":[\"field1\",\"field2\"]}}}");
var response = ElasticClient.PutSearchTemplate(templateRequest);
When using the template in a suggest collate:
.Collate(c => c
.Query(q => q
.Indexed("my_template")
)
.Prune()
)

- 2,832
- 1
- 22
- 40
Another question on similiar lines, Is PutSearchTemplateDescriptor the write method to call a pre-regsitered template?
I have registered the template to the .scripts but unable to find the right method to call the template from NEST client

- 168
- 11