title: Elasticsearch multiple suggestions with more advanced cases like matching prefix in the middle of a sentence
body: <p>My use case : I have a search bar when the user can type his query. I want to show multiple types of search suggestions to the user in addition to a regular query suggestion. For example, in the screenshot below, as you can see in this screenshot, you can see there are company sector, companies, and schools suggestions.</p>
  
  <p><a href="https://i.stack.imgur.com/FtmIp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FtmIp.png" alt="enter image description here"></a></p>
  
  <p>This is currently implemented using <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html#completion-suggester" rel="nofollow noreferrer">completion suggesters</a> and the following mappings (this is code from our Ruby implementation, but I believe you should be able to understand it easily)</p>
  
  <pre class="lang-rb prettyprint-override"><code>{
    _source: '',
    suggest: {
      text: query_from_the_user, # User query like "sec" to find "security" related matches 
      'school_names': {
        completion: {
          field: 'school_names_suggest',
        },
      },
      'companies': {
        completion: {
          field: 'company_name.suggest',
        },
      },
      'sectors': {
        completion: {
          field: sector_field_based_on_current_language(I18n.locale),
               # uses 'company_sector.french.suggest' when the user browses in french
        },
      },
    },
  }
  </code></pre>
  
  <p>Here are my mappings (this is written in Ruby as but I believe it shouldn't be too hard to mentally convert this to Elasticsearch JSON config</p>
  
  <pre class="lang-rb prettyprint-override"><code>indexes :company_name, type: 'text' do
    indexes :suggest, type: 'completion'
  end
  indexes :company_sector, type: 'object' do
    indexes :french, type: 'text' do
      indexes :suggest, type: 'completion'
    end
    indexes :english, type: 'text' do
      indexes :suggest, type: 'completion'
    end
  end
  indexes :school_names_suggest, type: 'completion'
  # sample Indexed JSON 
  { 
    company_name: "Christian Dior Couture",
    company_sector: {
      english: 'Milk sector',
      french: 'Secteur laitier'
    },
    school_names_suggest: ['Télécom ParisTech', 'Ecole Centrale Paris']
  }
  </code></pre>
  
  <p>The problem is the suggestion is not powerful enough and cannot autocomplete based on the middle of a sentence and provide additional results even after a perfect match. Here are some scenarios that I need to capture with my ES implementation</p>
  
  <h3>CASE 1 - Matching by prefix in the middle of a sentence</h3>
  
  <pre><code># documents
  [{ company_name: "Christian Dior Couture" }]
  # =&gt; A search term "Dior" should return this document because it matches by prefix on the second word
  </code></pre>
  
  <h3>CASE 2 - Provide results even after a perfect match</h3>
  
  <pre><code># documents
  [
    { company_name: "Crédit Agricole" },
    { company_name: "Crédit Agricole Pyrénées Gascogne" },
  ]
  # =&gt; A search term "Crédit Agricole" should return both documents (using the current implementation it only returns "Crédit Agricole"
  </code></pre>
  
  <p>Can I implement this using suggesters in Elasticsearch ? Or do I need to fall back to multiple <code>search</code> that would take advantage of the new <code>search-as-you-type</code> data type using a <code>query</code> as mentionned <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.x/search-as-you-type.html" rel="nofollow noreferrer">in the doc</a> ?</p>
  
  <p>I am using elasticsearch 7.1 on AWS and the Ruby driver (gem <code>elasticsearch-7.3.0</code>)</p>