# How to run multiple search templates using NEST

**URL:** <https://discuss.elastic.co/t/how-to-run-multiple-search-templates-using-nest/334933>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [June 1, 2023, 9:13am UTC](https://discuss.elastic.co/t/how-to-run-multiple-search-templates-using-nest/334933 "2023-06-01T09:13:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jacques\_du\_Plessis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jacques_du_plessis/32/35413_2.png) [@Jacques\_du\_Plessis](https://discuss.elastic.co/u/Jacques_du_Plessis)\
**Post date:** [June 1, 2023, 9:13am UTC](https://discuss.elastic.co/t/how-to-run-multiple-search-templates-using-nest/334933/1 "2023-06-01T09:13:20Z")

</div>

I am trying perform a multi-template search using NEST, and then read the reponses, but seems like it always returns null when I try to cast it to the POCO type.

The DSL query I run in Kibana looks like this. Just for reference.

```auto
GET user-menu-index,custom-form-index,employee-index/_msearch/template
{}
{"id":"user-menu-index-template","params":{"query":"profile","clauses":[]}}
{}
{"id":"custom-form-index-template","params":{"query":"basic","clauses":[]}}
{}
{"id":"employee-index-template","params":{"query":"brenda","clauses":[{"term":{"companyGroupId":1595}}]}}

```

In NEST it will like like this.

```auto
var indexTemplateRequest = new MultiSearchTemplateRequest
{
    Operations = new Dictionary<string, ISearchTemplateRequest>
    {
        {
            "custom-form-index", new SearchTemplateRequest("custom-form-index")
            {
                Id = "custom-form-index-template",
                Params = new Dictionary<string, object>
                {
                    { "query", query },
                    { "clauses", new List<object>() }
                }
            }
        }
    }
};

var multiSearchResponse = this.client.MultiSearchTemplate(indexTemplateRequest); <!-- I can see the results in the reponses, getting returned as a dictionary.

```

How can I access the reponses, from what I can find online, the following is what i need todo.

```auto
var responses = multiSearchResponse.GetResponse<CustomForm>("custom-form-index");

```

But the above always returns null. I thought maybe there is something wrong with my mappings. But if i change my query to the following

```auto
var response = this.client.SearchTemplate<CustomForm>(descriptor =>
                descriptor.Index("custom-form-index")
                    .Id("custom-form-index-template")
                    .Params(objects => objects
                        .Add("query", query)
                        .Add("from", from)
                        .Add("size", size)
                        .Add("clauses", "[]")));

```

I get the correct result back, but in this way i am just searching on one template i would like todo it multiple templates with one request.

My mappings file looks as follow.

```auto
[ElasticsearchType(RelationName = "customForm")] <!-- Not sure if the RelationName should be camel-case or not.
public class CustomForm
{
    [Text(Name = "companyId")] <!-- Added the types manually to see if it would make a difference
    public long CompanyId { get; set; }

    [Text(Name = "companyLevel")]
    public bool CompanyLevel { get; set; }

    [Text(Name = "employeeLevel")]
    public bool EmployeeLevel { get; set; }

    [Text(Name = "collectionName")]
    public string CollectionName { get; set; }

    [Text(Name = "customFormScreenType")]
    [Column("fkCustomFormScreenTypeID")]
    public CustomFormScreenTypes CustomFormScreenType { get; set; } = CustomFormScreenTypes.CustomForms;

    [Text(Name = "pageName")]
    public string PageName { get; set; }

    [Text(Name = "url")]
    public string Url { get; set; }
}

```

---

<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:** [June 29, 2023, 9:13am UTC](https://discuss.elastic.co/t/how-to-run-multiple-search-templates-using-nest/334933/2 "2023-06-29T09:13:33Z")

</div>

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