<p dir="auto">The majority of search frontends usually display the highlighted chunks below the hit title. The problem is that on non highlighting queries, such as a numerical range, no highlighting chunk will be brought back in the search. If you don't want your display to look bad, you usually display an excerpt of the beginning of the file, or of the first contiguous paragraph, etc... The easy way to do that is to always ask for the full field content in your ES query, but this is a very costly solution in any case (unnecessary memory and bandwidth).</p>
<p dir="auto">I would like to suggest an enhancement to ElasticSearch to add the possibility to get back a excerpt of the highlighted field in case the query doesn't highlight. The syntax would be:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&quot;highlight&quot; : {
    &quot;fields&quot; : {
        &quot;content&quot; : {
            &quot;fragment_size&quot; : 150,
            &quot;number_of_fragments&quot; : 3,
            &quot;fallback&quot; : &quot;excerpt_basic&quot; // or &quot;excerpt_firstparagraph&quot; or any other more advanced impl to come
        }
    }
}"><pre class="notranslate"><code class="notranslate">"highlight" : {
    "fields" : {
        "content" : {
            "fragment_size" : 150,
            "number_of_fragments" : 3,
            "fallback" : "excerpt_basic" // or "excerpt_firstparagraph" or any other more advanced impl to come
        }
    }
}
</code></pre></div>
<p dir="auto">Jérémie</p>
<p dir="auto">Highlighting is great as providing an <em>highlighted excerpt</em>, but if you run no query against one field, you will have no output at all.<br>
Highlighting could provide a non highlighted excerpt (some number of characters from the beginning of the value) as a fallback.<br>
This would be yield shorted answers than always asking for the whole field content (that may be quite long).</p>
<div class="highlight highlight-source-json notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  &quot;highlight&quot; : {
    &quot;fields&quot; : {
      &quot;text&quot; : {
        &quot;number_of_fragments&quot; : 3,
        &quot;size_of_fragments&quot; : 150,
        &quot;no_results&quot; : VALUE
      }
    }
  }
}"><pre class="notranslate">{
  <span class="pl-ent">"highlight"</span> : {
    <span class="pl-ent">"fields"</span> : {
      <span class="pl-ent">"text"</span> : {
        <span class="pl-ent">"number_of_fragments"</span> : <span class="pl-c1">3</span>,
        <span class="pl-ent">"size_of_fragments"</span> : <span class="pl-c1">150</span>,
        <span class="pl-ent">"no_results"</span> : <span class="pl-ii">VALUE</span>
      }
    }
  }
}</pre></div>
<p dir="auto">Where <em>VALUE</em> could take: <code class="notranslate">hide</code> (default), <code class="notranslate">show</code>, or a character count.<br>
Where <code class="notranslate">show</code> would be equivalent to setting the character count to <code class="notranslate">number_of_fragments * size_of_fragments</code>.</p>