# Explain feature is not working in a search template

**URL:** <https://discuss.elastic.co/t/explain-feature-is-not-working-in-a-search-template/321060>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [December 12, 2022, 5:29pm UTC](https://discuss.elastic.co/t/explain-feature-is-not-working-in-a-search-template/321060 "2022-12-12T17:29:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Randall-McRee](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@Randall-McRee](https://discuss.elastic.co/u/Randall-McRee)\
**Post date:** [December 12, 2022, 5:29pm UTC](https://discuss.elastic.co/t/explain-feature-is-not-working-in-a-search-template/321060/1 "2022-12-12T17:29:35Z")

</div>

When I put "explain=true" into a search template (as a parameter, so we can turn it on and off) it does not work. I see a similar problem long ago in .net...this is version 8.14.  
Following is simple kibana demonstrating the issue:

```auto
PUT /my-index-000001

POST /my-index-000001/_doc
{
  "@timestamp": "2099-11-15T13:12:00",
  "message": "explain bug",
  "user": {
    "id": "randall"
  }
}

PUT _scripts/my-search-template
{
  "script": {
    "lang": "mustache",
    "source": {
      "query": {
        "match": {
          "message": "{{query_string}}"
        }
      },
      "from": "{{from}}",
      "size": "{{size}}",
      "explain": "{{exp}}"
    },
    "params": {
      "query_string": "My query string",
      "exp" : true
    }
  }
}

POST _render/template
{
  "id": "my-search-template",
  "params": {
    "query_string": "bug",
    "from": 0,
    "size": 10,
    "exp":"true"
  }
}

GET my-index-000001/_search/template
{ /* finds one document but no explanation is given */
  "id": "my-search-template",
  "params": {
    "query_string": "bug",
    "from": 0,
    "size": 10,
    "exp":true
  }
}

GET my-index-000001/_search
{ /* this works, explanation is offered */
  "query": {
    "match": {
      "message": "bug"
    }
  },
  "from": "0",
  "size": "10",
  "explain": "true"
}

```

---

<div class="post-metadata">

**Author:** ![Randall-McRee](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@Randall-McRee](https://discuss.elastic.co/u/Randall-McRee)\
**Post date:** [December 12, 2022, 6:18pm UTC](https://discuss.elastic.co/t/explain-feature-is-not-working-in-a-search-template/321060/2 "2022-12-12T18:18:23Z")

</div>

Dyslexia: this is version 8.4.1

---

<div class="post-metadata">

**Author:** ![canelia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/canelia/32/141857_2.png) [@canelia](https://discuss.elastic.co/u/canelia)\
**Post date:** [December 13, 2022, 8:40am UTC](https://discuss.elastic.co/t/explain-feature-is-not-working-in-a-search-template/321060/3 "2022-12-13T08:40:19Z")

</div>

try it. Hope it works

```auto

GET my-index-000001/_search/template
{ 
  "id": "my-search-template",
  "params": {
    "query_string": "bug",
    "from": 0,
    "size": 10
  },
  "explain": true
}

```

---

<div class="post-metadata">

**Author:** ![Randall-McRee](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@Randall-McRee](https://discuss.elastic.co/u/Randall-McRee)\
**Post date:** [December 13, 2022, 4:26pm UTC](https://discuss.elastic.co/t/explain-feature-is-not-working-in-a-search-template/321060/4 "2022-12-13T16:26:39Z")

</div>

Thanks, that does work. Strange that \_source and other search parameters do not work in that way. I guess this is a documentation issue.

---

<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:** [January 10, 2023, 4:27pm UTC](https://discuss.elastic.co/t/explain-feature-is-not-working-in-a-search-template/321060/5 "2023-01-10T16:27:37Z")

</div>

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