How to use Nest Library (C#) for msearch/template

Hi guys,
I have a saved template for msearch thats look like:

POST _scripts/t1
{
  "script": {
    "lang": "mustache",
    "source": {
      "query": {
        "match_phrase": {
          "{{field}}": "{{value}}"
        }
      }
    }
  }
}

I'm trying to call saved template in Elasticsearch via:

POST processlog/_msearch/template
{}
{ "id": "t1", "params": { "field": "Envrionment", "value": "Test" }}
{}
{ "id": "t1", "params": { "field": "Envrionment", "value": "Test" }}

Works perfect!

But if I try to rebuild it in C#, there a no options for that..

elasticclient.MultiSearchTemplate(mst => mst
        .Index("processlog")
        .????

The Documentation for MultiSearchTemplate is not available for version 6.X.

Anybody an idea, how it could look like in C#?

You can send a multisearch template request with

var client = new ElasticClient();

var response = client.MultiSearchTemplate(ms => ms
    .Template<object>("template_1", st => st
        .AllIndices()
        .AllTypes()
        .Id("t1")
        .Params(d => d
            .Add("field", "Envrionment")
            .Add("value", "Test")
        )
    )
    .Template<object>("template_2", st => st
        .AllIndices()
        .AllTypes()
        .Id("t1")
        .Params(d => d
            .Add("field", "Envrionment")
            .Add("value", "Test")
        )
    )
);

var firstSearchResponse = response.GetResponse<object>("template_1");
var secondSearchResponse = response.GetResponse<object>("template_2");

I've used object here to represent the type to which the documents in each search will be deserialized into, but you can use whatever class makes sense.

This will send the following request

POST http://localhost:9200/_msearch/template
{"index":"_all"}
{"id":"t1","params":{"field":"Envrionment","value":"Test"}}
{"index":"_all"}
{"id":"t1","params":{"field":"Envrionment","value":"Test"}}

Note that NEST inserts the "_all" index name for all indices, which should act the same as not specifying the index.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.