<p dir="auto">The context suggester is returning only one document when two documents have the same input (the higher score, I guess). Also the payload is wrong.</p>
<p dir="auto">1- create an index called "services" with suggest_field mapped as "completion" with payloads</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="POST services
{
  &quot;mappings&quot;: {
    &quot;service&quot;: {
      &quot;properties&quot;: {
        &quot;name&quot;: {
          &quot;type&quot;: &quot;string&quot;
        },
        &quot;suggest_field&quot;: {
          &quot;type&quot;: &quot;completion&quot;,
          &quot;payloads&quot;: true,
          &quot;context&quot;: {
            &quot;color&quot;: {
              &quot;type&quot;: &quot;category&quot;
            }
          }
        }
      }
    }
  }
}"><pre class="notranslate"><code class="notranslate">POST services
{
  "mappings": {
    "service": {
      "properties": {
        "name": {
          "type": "string"
        },
        "suggest_field": {
          "type": "completion",
          "payloads": true,
          "context": {
            "color": {
              "type": "category"
            }
          }
        }
      }
    }
  }
}
</code></pre></div>
<p dir="auto">2- index a document with id = 1. The input of the completion is "same_input" with weight = 100 and payload {"url": "first_document"}</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PUT services/service/1
{
    &quot;name&quot;: &quot;same_input&quot;,
    &quot;suggest_field&quot;: {
        &quot;input&quot;: &quot;same_input&quot;,
        &quot;weight&quot;: 100,
        &quot;payload&quot;: {
          &quot;url&quot;: &quot;first_document&quot;
        },
        &quot;context&quot;: {
            &quot;color&quot;: [&quot;red&quot;, &quot;yellow&quot;]
        }
    }
}"><pre class="notranslate"><code class="notranslate">PUT services/service/1
{
    "name": "same_input",
    "suggest_field": {
        "input": "same_input",
        "weight": 100,
        "payload": {
          "url": "first_document"
        },
        "context": {
            "color": ["red", "yellow"]
        }
    }
}
</code></pre></div>
<p dir="auto">3- index a document with id = 2. The input of the completion is "same_input" too with weight = 200 and payload {"url": "second_document"}</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PUT services/service/2
{
    &quot;name&quot;: &quot;same_input&quot;,
    &quot;suggest_field&quot;: {
        &quot;input&quot;: &quot;same_input&quot;,
        &quot;weight&quot;: 200,
        &quot;payload&quot;: {
          &quot;url&quot;: &quot;second_document&quot;
        },
        &quot;context&quot;: {
            &quot;color&quot;: [&quot;red&quot;, &quot;green&quot;]
        }
    }
}"><pre class="notranslate"><code class="notranslate">PUT services/service/2
{
    "name": "same_input",
    "suggest_field": {
        "input": "same_input",
        "weight": 200,
        "payload": {
          "url": "second_document"
        },
        "context": {
            "color": ["red", "green"]
        }
    }
}
</code></pre></div>
<p dir="auto">4- query for suggest using "same_input" as text</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="POST services/_suggest?pretty'
{
    &quot;suggest&quot; : {
        &quot;text&quot; : &quot;same_input&quot;,
        &quot;completion&quot; : {
            &quot;field&quot; : &quot;suggest_field&quot;,
            &quot;size&quot;: 10,
            &quot;context&quot;: {
                &quot;color&quot;: [&quot;red&quot;]
            }
        }
    }
}"><pre class="notranslate"><code class="notranslate">POST services/_suggest?pretty'
{
    "suggest" : {
        "text" : "same_input",
        "completion" : {
            "field" : "suggest_field",
            "size": 10,
            "context": {
                "color": ["red"]
            }
        }
    }
}
</code></pre></div>
<p dir="auto">5 - the response includes only one document with the score 200, which is the weigth of the document id = 2 but with the payload of the document of id = 1 when using context "red".</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
   &quot;_shards&quot;: {
      &quot;total&quot;: 5,
      &quot;successful&quot;: 5,
      &quot;failed&quot;: 0
   },
   &quot;suggest&quot;: [
      {
         &quot;text&quot;: &quot;same_input&quot;,
         &quot;offset&quot;: 0,
         &quot;length&quot;: 10,
         &quot;options&quot;: [
            {
               &quot;text&quot;: &quot;same_input&quot;,
               &quot;score&quot;: 200,
               &quot;payload&quot;: {
                  &quot;url&quot;: &quot;first_document&quot;
               }
            }
         ]
      }
   ]
}"><pre class="notranslate"><code class="notranslate">{
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "suggest": [
      {
         "text": "same_input",
         "offset": 0,
         "length": 10,
         "options": [
            {
               "text": "same_input",
               "score": 200,
               "payload": {
                  "url": "first_document"
               }
            }
         ]
      }
   ]
}
</code></pre></div>
<p dir="auto">When I create multiple documents which have the same output value in the completion field, a suggest completion request only retrieves one object.<br>
I guess it is a feature, however, once we may set different payloads to those documents, it would make sense to retrieve multiple suggestions with the same output.</p>
<p dir="auto">My environment settings:<br>
ElasticSearch version number: <code class="notranslate">1.0.0.Beta1</code><br>
Lucene version: <code class="notranslate">4.5.1</code></p>
<p dir="auto">In the following example, I create an index with two documents. Each document has a different value in the payload, but the same output and input.<br>
Performing a suggestion completion request, only one document is retrieved.</p>
<p dir="auto">Scripts:</p>
<h2 dir="auto">Create and populate index</h2>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="curl -XDELETE 'localhost:9200/notebookindex'

curl -XPUT localhost:9200/notebookindex

curl -XPUT localhost:9200/notebookindex/friend/_mapping -d '{
  &quot;friend&quot; : {
        &quot;properties&quot; : {
            &quot;name&quot; : { &quot;type&quot; : &quot;string&quot; },
            &quot;suggestField&quot; : { &quot;type&quot; : &quot;completion&quot;, &quot;payloads&quot; : true }
        }
    }
}'

curl -XPUT 'localhost:9200/notebookindex/friend/1' -d ' {
  &quot;name&quot;: &quot;james smith&quot;,
  &quot;suggestField&quot;: {
    &quot;input&quot;: [&quot;james&quot;, &quot;smith&quot;, &quot;james smith&quot;],
    &quot;output&quot;: &quot;james smith&quot;,
    &quot;payload&quot;: {&quot;id&quot;: &quot;1&quot;, &quot;phone&quot;: &quot;555-55555&quot;}
  }
}'

curl -XPUT 'localhost:9200/notebookindex/friend/2' -d '{
  &quot;name&quot;: &quot;james smith&quot;,
  &quot;suggestField&quot;: {
    &quot;input&quot;: [&quot;james&quot;, &quot;smith&quot;, &quot;james smith&quot;],
    &quot;output&quot;: &quot;james smith&quot;,
    &quot;payload&quot;: {&quot;id&quot;: &quot;2&quot;, &quot;phone&quot;: &quot;444-44444&quot;}
  }
}'"><pre class="notranslate">curl -XDELETE <span class="pl-s"><span class="pl-pds">'</span>localhost:9200/notebookindex<span class="pl-pds">'</span></span>

curl -XPUT localhost:9200/notebookindex

curl -XPUT localhost:9200/notebookindex/friend/_mapping -d <span class="pl-s"><span class="pl-pds">'</span>{</span>
<span class="pl-s">  "friend" : {</span>
<span class="pl-s">        "properties" : {</span>
<span class="pl-s">            "name" : { "type" : "string" },</span>
<span class="pl-s">            "suggestField" : { "type" : "completion", "payloads" : true }</span>
<span class="pl-s">        }</span>
<span class="pl-s">    }</span>
<span class="pl-s">}<span class="pl-pds">'</span></span>

curl -XPUT <span class="pl-s"><span class="pl-pds">'</span>localhost:9200/notebookindex/friend/1<span class="pl-pds">'</span></span> -d <span class="pl-s"><span class="pl-pds">'</span> {</span>
<span class="pl-s">  "name": "james smith",</span>
<span class="pl-s">  "suggestField": {</span>
<span class="pl-s">    "input": ["james", "smith", "james smith"],</span>
<span class="pl-s">    "output": "james smith",</span>
<span class="pl-s">    "payload": {"id": "1", "phone": "555-55555"}</span>
<span class="pl-s">  }</span>
<span class="pl-s">}<span class="pl-pds">'</span></span>

curl -XPUT <span class="pl-s"><span class="pl-pds">'</span>localhost:9200/notebookindex/friend/2<span class="pl-pds">'</span></span> -d <span class="pl-s"><span class="pl-pds">'</span>{</span>
<span class="pl-s">  "name": "james smith",</span>
<span class="pl-s">  "suggestField": {</span>
<span class="pl-s">    "input": ["james", "smith", "james smith"],</span>
<span class="pl-s">    "output": "james smith",</span>
<span class="pl-s">    "payload": {"id": "2", "phone": "444-44444"}</span>
<span class="pl-s">  }</span>
<span class="pl-s">}<span class="pl-pds">'</span></span></pre></div>
<h2 dir="auto">Search 1: look for friends starting with <code class="notranslate">j</code></h2>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="curl -XPOST 'localhost:9200/notebookindex/_suggest?pretty' -d '{
  &quot;my-friends-suggest&quot;: {
    &quot;text&quot;: &quot;j&quot;,
    &quot;completion&quot;: {
      &quot;field&quot;: &quot;suggestField&quot;
    }
  }
}'"><pre class="notranslate">curl -XPOST <span class="pl-s"><span class="pl-pds">'</span>localhost:9200/notebookindex/_suggest?pretty<span class="pl-pds">'</span></span> -d <span class="pl-s"><span class="pl-pds">'</span>{</span>
<span class="pl-s">  "my-friends-suggest": {</span>
<span class="pl-s">    "text": "j",</span>
<span class="pl-s">    "completion": {</span>
<span class="pl-s">      "field": "suggestField"</span>
<span class="pl-s">    }</span>
<span class="pl-s">  }</span>
<span class="pl-s">}<span class="pl-pds">'</span></span></pre></div>
<p dir="auto">Only one <code class="notranslate">James</code> is found, even though there are two documents matching the suggestion.</p>
<div class="highlight highlight-source-json notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  &quot;_shards&quot; : {
    &quot;total&quot; : 5,
    &quot;successful&quot; : 5,
    &quot;failed&quot; : 0
  },
  &quot;my-friends-suggest&quot; : [ {
    &quot;text&quot; : &quot;j&quot;,
    &quot;offset&quot; : 0,
    &quot;length&quot; : 1,
    &quot;options&quot; : [ {
      &quot;text&quot; : &quot;james smith&quot;,
      &quot;score&quot; : 1.0, &quot;payload&quot; : {&quot;id&quot;:&quot;2&quot;,&quot;phone&quot;:&quot;444-44444&quot;}
    } ]
  } ]
}"><pre class="notranslate">{
  <span class="pl-ent">"_shards"</span> : {
    <span class="pl-ent">"total"</span> : <span class="pl-c1">5</span>,
    <span class="pl-ent">"successful"</span> : <span class="pl-c1">5</span>,
    <span class="pl-ent">"failed"</span> : <span class="pl-c1">0</span>
  },
  <span class="pl-ent">"my-friends-suggest"</span> : [ {
    <span class="pl-ent">"text"</span> : <span class="pl-s"><span class="pl-pds">"</span>j<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"offset"</span> : <span class="pl-c1">0</span>,
    <span class="pl-ent">"length"</span> : <span class="pl-c1">1</span>,
    <span class="pl-ent">"options"</span> : [ {
      <span class="pl-ent">"text"</span> : <span class="pl-s"><span class="pl-pds">"</span>james smith<span class="pl-pds">"</span></span>,
      <span class="pl-ent">"score"</span> : <span class="pl-c1">1.0</span>, <span class="pl-ent">"payload"</span> : {<span class="pl-ent">"id"</span>:<span class="pl-s"><span class="pl-pds">"</span>2<span class="pl-pds">"</span></span>,<span class="pl-ent">"phone"</span>:<span class="pl-s"><span class="pl-pds">"</span>444-44444<span class="pl-pds">"</span></span>}
    } ]
  } ]
}</pre></div>
<h2 dir="auto">Removal and Search 2: remove the <code class="notranslate">James</code> (<code class="notranslate">id 2</code>) previously found and look for friends starting with <code class="notranslate">j</code></h2>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="curl -XDELETE 'localhost:9200/notebookindex/friend/2'

curl -XPOST 'localhost:9200/notebookindex/_suggest?pretty' -d '{
  &quot;my-friends-suggest&quot;: {
    &quot;text&quot;: &quot;j&quot;,
    &quot;completion&quot;: {
      &quot;field&quot;: &quot;suggestField&quot;
    }
  }
}'"><pre class="notranslate">curl -XDELETE <span class="pl-s"><span class="pl-pds">'</span>localhost:9200/notebookindex/friend/2<span class="pl-pds">'</span></span>

curl -XPOST <span class="pl-s"><span class="pl-pds">'</span>localhost:9200/notebookindex/_suggest?pretty<span class="pl-pds">'</span></span> -d <span class="pl-s"><span class="pl-pds">'</span>{</span>
<span class="pl-s">  "my-friends-suggest": {</span>
<span class="pl-s">    "text": "j",</span>
<span class="pl-s">    "completion": {</span>
<span class="pl-s">      "field": "suggestField"</span>
<span class="pl-s">    }</span>
<span class="pl-s">  }</span>
<span class="pl-s">}<span class="pl-pds">'</span></span></pre></div>
<p dir="auto">The other <code class="notranslate">James</code> is found.</p>
<div class="highlight highlight-source-json notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  &quot;_shards&quot; : {
    &quot;total&quot; : 5,
    &quot;successful&quot; : 5,
    &quot;failed&quot; : 0
  },
  &quot;my-friends-suggest&quot; : [ {
    &quot;text&quot; : &quot;j&quot;,
    &quot;offset&quot; : 0,
    &quot;length&quot; : 1,
    &quot;options&quot; : [ {
      &quot;text&quot; : &quot;james smith&quot;,
      &quot;score&quot; : 1.0, &quot;payload&quot; : {&quot;id&quot;:&quot;1&quot;,&quot;phone&quot;:&quot;555-55555&quot;}
    } ]
  } ]
}"><pre class="notranslate">{
  <span class="pl-ent">"_shards"</span> : {
    <span class="pl-ent">"total"</span> : <span class="pl-c1">5</span>,
    <span class="pl-ent">"successful"</span> : <span class="pl-c1">5</span>,
    <span class="pl-ent">"failed"</span> : <span class="pl-c1">0</span>
  },
  <span class="pl-ent">"my-friends-suggest"</span> : [ {
    <span class="pl-ent">"text"</span> : <span class="pl-s"><span class="pl-pds">"</span>j<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"offset"</span> : <span class="pl-c1">0</span>,
    <span class="pl-ent">"length"</span> : <span class="pl-c1">1</span>,
    <span class="pl-ent">"options"</span> : [ {
      <span class="pl-ent">"text"</span> : <span class="pl-s"><span class="pl-pds">"</span>james smith<span class="pl-pds">"</span></span>,
      <span class="pl-ent">"score"</span> : <span class="pl-c1">1.0</span>, <span class="pl-ent">"payload"</span> : {<span class="pl-ent">"id"</span>:<span class="pl-s"><span class="pl-pds">"</span>1<span class="pl-pds">"</span></span>,<span class="pl-ent">"phone"</span>:<span class="pl-s"><span class="pl-pds">"</span>555-55555<span class="pl-pds">"</span></span>}
    } ]
  } ]
}</pre></div>