# Using SearchTemplates in Elasticsearch 6.6

**URL:** <https://discuss.elastic.co/t/using-searchtemplates-in-elasticsearch-6-6/167732>\
**Category:** Elasticsearch\
**Created:** [February 10, 2019, 1:59am UTC](https://discuss.elastic.co/t/using-searchtemplates-in-elasticsearch-6-6/167732 "2019-02-10T01:59:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rennishj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rennishj/32/42172_2.png) [@rennishj](https://discuss.elastic.co/u/rennishj)\
**Post date:** [February 10, 2019, 1:59am UTC](https://discuss.elastic.co/t/using-searchtemplates-in-elasticsearch-6-6/167732/1 "2019-02-10T01:59:36Z")

</div>

All,  
I've been trying to parametrize **size** and **from** in the searchtemplate and invoke the template from NEST 6.6.  
I can't get the following searchtemplate to work(It is returning all results) while invoking the template. We are trying to limit the NEST queries we are writing and moving all the queries into searchtemplates. Someone please let me know whats wrong with this or is it even possible to parametrize the size and from in the template. I saw a simlar question [C# NEST 5 Search with template](https://discuss.elastic.co/t/c-nest-5-search-with-template/104074) for NEST 5.x, but the same NEST api seem slike is discontinued in 6.6. I would like to do this through SearchTemplate though. Please see the details below

Template definition

```
PUT _scripts/customers_by_email
{
  "script": {
    "lang": "mustache",
    "source": """
    {
      "from":"{{from}}{{^from}}0{{/from}}",
      "size":"{{size}}{{^size}}20{{/size}}"
    },
    {
      "query":{
        "bool":{
          "filter":{
            "terms":{
              "email":
              {{#toJson}}emails{{/toJson}}
            }
          }
        }
      }
    }"""
  }
}

GET _render/template
{
  "id":"customers_by_email",
  "params": {
    "emails":["rennishj@test.com"]
  }
}

GET customer/_search/template
{
  "id":"customers_by_email",
  "params": {
    "emails":["rennishj@test.com"]
  }
}

```

customer mapping:

**email is keyword**

**sample customer document:**

```
PUT customer/_doc/4
{
  "firstName":"Niah",
  "lastName":"Joseph",
  "email":["niah@test.com"]
}

```

**customer mapping details:**

```
PUT _template/customer_template
{
  "order": 0,
  "index_patterns": ["customer*"],
  "settings": {
    "index": {
      "analysis": {
        "filter": {
          "autoComplete_filter": {
            "type": "edge_ngram",
            "min_gram": "2",
            "max_gram": "20"
          }
        },
        "analyzer": {
          "autoComplete": {
            "filter": ["lowercase", "asciifolding","autoComplete_filter"],
            "type": "custom",
            "tokenizer": "whitespace"
          },
          "default": {
            "filter": ["lowercase", "asciifolding"],
            "type": "custom",
            "tokenizer": "whitespace"
          }
        }
      },
      "number_of_shards": "3",
      "number_of_replicas": "1"
    }
  },
  "mappings": {
    "_doc": {
      "dynamic": false,
      "properties": {
        "firstName": {
          "type": "keyword",
          "fields": {
            "search": {
              "type": "text",
              "analyzer": "autoComplete",
              "search_analyzer": "default"
            }
          }
        },
        "lastName": {
          "type": "keyword",
          "fields": {
            "search": {
              "type": "text",
              "analyzer": "autoComplete",
              "search_analyzer": "default"
            }
          }
        },
        "email": {
          "type": "keyword"
        }
      }
    }
  }
}

PUT customer/_doc/4
{
  "firstName":"Niah",
  "lastName":"Joseph",
  "email":["niah@test.com"]
}

```

Invoking the template from NEST

```
List<string> emails = new List<string>(){"rennishj@test.com"};
var searchResponse = client.SearchTemplate<object>(st => st
    .Index("customer")
    .Id("customers_by_email")
    .Params(p => p
        .Add("emails", emails.ToArray())
        .Add("from", 0)		
        .Add("size", 50)
    )
);
```

---

<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:** [March 10, 2019, 1:59am UTC](https://discuss.elastic.co/t/using-searchtemplates-in-elasticsearch-6-6/167732/2 "2019-03-10T01:59:46Z")

</div>

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