<div class="highlight highlight-source-httpspec notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="PUT _template/test
{
  &quot;template&quot;: &quot;i*&quot;,
  &quot;settings&quot;: {
    &quot;analysis&quot;: {
      &quot;analyzer&quot;: {
        &quot;custom&quot;: {
          &quot;type&quot;: &quot;custom&quot;,
          &quot;tokenizer&quot;: &quot;keyword&quot;
        }
      }
    }
  }
}

PUT /_template/test1
{
  &quot;template&quot;: &quot;index*&quot;,
  &quot;mappings&quot;: {
    &quot;type&quot;: {
      &quot;properties&quot;: {
        &quot;message&quot;: {
          &quot;type&quot;: &quot;text&quot;,
          &quot;analyzer&quot;: &quot;custom&quot;
        }
      }
    }
  }
}"><pre class="notranslate"><span class="pl-k">PUT</span> <span class="pl-ii">_template/test</span>
{
  <span class="pl-ent">"template"</span>: <span class="pl-s"><span class="pl-pds">"</span>i*<span class="pl-pds">"</span></span>,
  <span class="pl-ent">"settings"</span>: {
    <span class="pl-ent">"analysis"</span>: {
      <span class="pl-ent">"analyzer"</span>: {
        <span class="pl-ent">"custom"</span>: {
          <span class="pl-ent">"type"</span>: <span class="pl-s"><span class="pl-pds">"</span>custom<span class="pl-pds">"</span></span>,
          <span class="pl-ent">"tokenizer"</span>: <span class="pl-s"><span class="pl-pds">"</span>keyword<span class="pl-pds">"</span></span>
        }
      }
    }
  }
}

<span class="pl-k">PUT</span><span class="pl-c1"> /_template/test1</span>
{
  <span class="pl-ent">"template"</span>: <span class="pl-s"><span class="pl-pds">"</span>index*<span class="pl-pds">"</span></span>,
  <span class="pl-ent">"mappings"</span>: {
    <span class="pl-ent">"type"</span>: {
      <span class="pl-ent">"properties"</span>: {
        <span class="pl-ent">"message"</span>: {
          <span class="pl-ent">"type"</span>: <span class="pl-s"><span class="pl-pds">"</span>text<span class="pl-pds">"</span></span>,
          <span class="pl-ent">"analyzer"</span>: <span class="pl-s"><span class="pl-pds">"</span>custom<span class="pl-pds">"</span></span>
        }
      }
    }
  }
}</pre></div>
<p dir="auto">The first template, which can be thought of as the parent template, defines something that is used by the second template: a custom analyzer. The template validator appears to only consider the template as a standalone one, which means that the analyzer does not exist, thus returning:</p>
<div class="highlight highlight-source-json notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  &quot;error&quot;: {
    &quot;root_cause&quot;: [
      {
        &quot;type&quot;: &quot;mapper_parsing_exception&quot;,
        &quot;reason&quot;: &quot;analyzer [custom] not found for field [message]&quot;
      }
    ],
    &quot;type&quot;: &quot;mapper_parsing_exception&quot;,
    &quot;reason&quot;: &quot;Failed to parse mapping [type]: analyzer [custom] not found for field [message]&quot;,
    &quot;caused_by&quot;: {
      &quot;type&quot;: &quot;mapper_parsing_exception&quot;,
      &quot;reason&quot;: &quot;analyzer [custom] not found for field [message]&quot;
    }
  },
  &quot;status&quot;: 400
}"><pre class="notranslate">{
  <span class="pl-ent">"error"</span>: {
    <span class="pl-ent">"root_cause"</span>: [
      {
        <span class="pl-ent">"type"</span>: <span class="pl-s"><span class="pl-pds">"</span>mapper_parsing_exception<span class="pl-pds">"</span></span>,
        <span class="pl-ent">"reason"</span>: <span class="pl-s"><span class="pl-pds">"</span>analyzer [custom] not found for field [message]<span class="pl-pds">"</span></span>
      }
    ],
    <span class="pl-ent">"type"</span>: <span class="pl-s"><span class="pl-pds">"</span>mapper_parsing_exception<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"reason"</span>: <span class="pl-s"><span class="pl-pds">"</span>Failed to parse mapping [type]: analyzer [custom] not found for field [message]<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"caused_by"</span>: {
      <span class="pl-ent">"type"</span>: <span class="pl-s"><span class="pl-pds">"</span>mapper_parsing_exception<span class="pl-pds">"</span></span>,
      <span class="pl-ent">"reason"</span>: <span class="pl-s"><span class="pl-pds">"</span>analyzer [custom] not found for field [message]<span class="pl-pds">"</span></span>
    }
  },
  <span class="pl-ent">"status"</span>: <span class="pl-c1">400</span>
}</pre></div>
<p dir="auto">The template validation should combine matching templates like normal index creation works, which would to ensure that the <em>entire</em> chain is valid or invalid.</p>
<p dir="auto"><strong>Workaround</strong></p>
<p dir="auto">There is a workaround, which is to manually apply necessary pieces to the sub-template (e.g., duplicating the analyzer in it, which will be only appear once in the resulting index).</p>
<p dir="auto">Given the following document</p>
<p dir="auto"><code class="notranslate">{ ... "input" : ["foobar", "barfoo", "foo"] ... }</code></p>
<p dir="auto">and the query <code class="notranslate">foo</code>, the document will show up twice in the result set when using completion suggester. I'm currently using a custom method to clean my input data to make sure the same prefix is not being used twice for a given document but it somehow feels wrong. With a regular search a document will also not show multiple times if a keyword is contained more than once in the document, is the completion suggester working this way by design?</p>