title: How to implement higher ranking for search hits whose terms occur earlier in the text
body: <p>I'm trying to implement search-as-you-type movie title search. I wish my search to rank titles which start with entered prefix higher than those which has this prefix in a latter terms.</p>
  <p>For example, for query &quot;<strong>termi</strong>&quot; I expect results in the following order:</p>
  <ol>
  <li><strong>Termi</strong>nal</li>
  <li><strong>Termi</strong>nator</li>
  <li>Lady-<strong>termi</strong>nator</li>
  <li>Quarantine 2: <strong>Termi</strong>nal</li>
  </ol>
  <p>It is also essential to allow misprints in query terms that user has already fully typed (e.g in <em><strong>Pirats</strong> of the Carib</em>... first term should be considered as &quot;<strong>pirates</strong>&quot;)</p>
  <p>I'm using the following mapping in my index:</p>
  <pre><code>{
          &quot;mappings&quot;: {
              &quot;dynamic&quot;: False,
              &quot;properties&quot;: {      
                  &quot;title&quot;: {
                      &quot;type&quot;: &quot;text&quot;,
                  },       
                  &quot;title_on_the_fly&quot;: {&quot;type&quot;: &quot;search_as_you_type&quot;},
              },
          }
      } 
  </code></pre>
  <p>And this query:</p>
  <pre><code>&quot;query&quot;: {
              &quot;bool&quot;: {
                  &quot;should&quot;: [
                      # --------- title -------------------
                      {
                          &quot;multi_match&quot;: {
                              &quot;query&quot;: query,                 
                              &quot;type&quot;: &quot;phrase_prefix&quot;,
                              &quot;fields&quot;: [
                                  &quot;title_on_the_fly&quot;,
                                  &quot;title_on_the_fly._2gram&quot;,
                                  &quot;title_on_the_fly._3gram&quot;,
                              ],
                              &quot;operator&quot;: &quot;and&quot;,
                              &quot;boost&quot;: 15,
                          }
                      },
                      {
                          &quot;multi_match&quot;: {
                              &quot;query&quot;: query,
                              &quot;type&quot;: &quot;bool_prefix&quot;,
                              &quot;fields&quot;: [
                                  &quot;title_on_the_fly&quot;,
                                  &quot;title_on_the_fly._2gram&quot;,
                                  &quot;title_on_the_fly._3gram&quot;,
                              ],
                              &quot;fuzziness&quot;: &quot;AUTO&quot;,
                              &quot;operator&quot;: &quot;and&quot;,
                              &quot;boost&quot;: 8,
                          }
                      },
                      
                      # ---------- Fuzzy single word title ------
                      {
                          &quot;match&quot;: {
                              &quot;title&quot;: {
                                  &quot;query&quot;: query,
                                  &quot;fuzziness&quot;: &quot;AUTO&quot;,
                                  &quot;operator&quot;: &quot;and&quot;,
                                  &quot;boost&quot;: 6,
                              }
                          }
                      },
                      
                  ],
                  &quot;minimum_should_match&quot;: 1,
              }
          },
  </code></pre>
  <p>My current query is doing well with misprints and prefix search, but ignores the position of hitting term, so, for example, I could sometimes get on <strong>termi</strong> query something like:</p>
  <ol>
  <li>Lady-<strong>termi</strong>nator</li>
  <li><strong>Termi</strong>nator</li>
  <li>...</li>
  </ol>
  <p>Is there any way to fix ranking? How should I change mappings/query to achieve this?</p>