Explain feature is not working in a search template

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:

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"
}

Dyslexia: this is version 8.4.1

try it. Hope it works


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

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

1 Like

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