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

**URL:** <https://discuss.elastic.co/t/how-to-use-nest-library-c-for-msearch-template/163575>\
**Category:** Elasticsearch\
**Created:** [January 9, 2019, 3:55pm UTC](https://discuss.elastic.co/t/how-to-use-nest-library-c-for-msearch-template/163575 "2019-01-09T15:55:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nico92](https://avatars.discourse-cdn.com/v4/letter/n/a87d85/32.png) [@Nico92](https://discuss.elastic.co/u/Nico92)\
**Post date:** [January 9, 2019, 3:55pm UTC](https://discuss.elastic.co/t/how-to-use-nest-library-c-for-msearch-template/163575/1 "2019-01-09T15:55:06Z")

</div>

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#?

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [January 11, 2019, 10:43pm UTC](https://discuss.elastic.co/t/how-to-use-nest-library-c-for-msearch-template/163575/2 "2019-01-11T22:43:26Z")

</div>

You can send a multisearch template request with

```auto
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

```json
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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 8, 2019, 10:43pm UTC](https://discuss.elastic.co/t/how-to-use-nest-library-c-for-msearch-template/163575/3 "2019-02-08T22:43:27Z")

</div>

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