# Completion suggester suggesting full document

**URL:** <https://discuss.elastic.co/t/completion-suggester-suggesting-full-document/75048>\
**Category:** Elasticsearch\
**Created:** [February 14, 2017, 2:22pm UTC](https://discuss.elastic.co/t/completion-suggester-suggesting-full-document/75048 "2017-02-14T14:22:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zaid\_Amir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zaid_amir/32/54679_2.png) [@Zaid\_Amir](https://discuss.elastic.co/u/Zaid_Amir)\
**Post date:** [February 14, 2017, 2:22pm UTC](https://discuss.elastic.co/t/completion-suggester-suggesting-full-document/75048/1 "2017-02-14T14:22:11Z")

</div>

Hi,

I am migrating from ES 1.7 to 5.2 and as I am testing I noticed that the new completion suggester does not work as it used to in 1.7.

In 1.7 when I invoke the \_suggest API the response returned a set of options matching the distinct words/entries found in the completion field.

In 5.2, I am getting the entire document inside the options object.

For example if my completion field has the following array stored:

"input": ["winter", "windows", "widow"]

In 1.7 when I invoke the \_suggest API I used to get this response:

```
{
	"_shards" : {
		"total" : 1,
		"successful" : 1,
		"failed" : 0
	},
	"tagsuggest" : [{
			"text" : "wi",
			"offset" : 0,
			"length" : 2,
			"options" : [{
					"text" : "widow",
					"score" : 3.0
				}, {
					"text" : "windows",
					"score" : 3.0
				}, {
					"text" : "winter",
					"score" : 3.0
				}
			]
		}
	]
}

```

Yet in 5.2 when I do a suggest search I am getting the full document:

```
{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": 0,
    "hits": []
  },
  "suggest": {
    "tagssuggest": [
      {
        "text": "wi",
        "offset": 0,
        "length": 3,
        "options": [
          {
            "text": "winning",
            "_index": "myindex",
            "_type": "mytype",
            "_id": "123456",
            "_score": 1,
            "_source": {
              "tags": [
                "windows",
                "winter",
                "winning"
              ]
              "tagssuggest": {
                "input": [
                  "windows",
				  "winter",
                  "winning"
                ],
                "contexts": {
                  "user": [
                    "1"
                  ]
                }
              }
            },
            "contexts": {
              "user": [
                "1"
              ]
            }
          }
        ]
      }
    ]
  }
}

```

How can I go about returning distinct matching words from the suggest field?

Regards

---

<div class="post-metadata">

**Author:** ![tanguy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tanguy/32/6030_2.png) [@tanguy](https://discuss.elastic.co/u/tanguy)\
**Post date:** [February 14, 2017, 2:33pm UTC](https://discuss.elastic.co/t/completion-suggester-suggesting-full-document/75048/2 "2017-02-14T14:33:42Z")

</div>

Hi,

Suggesters have changed a lot since 1.7. In 5.x they are now document oriented, ie the completion suggester now return the document from where suggestions have been found (see [https://www.elastic.co/guide/en/elasticsearch/reference/5.0/breaking\_50\_suggester.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/breaking_50_suggester.html)).

You might either want to filter the source of the suggested documents (see [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html)) or use a Term suggester instead (see [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-term.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-term.html))

Hope this helps

---

<div class="post-metadata">

**Author:** ![Zaid\_Amir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zaid_amir/32/54679_2.png) [@Zaid\_Amir](https://discuss.elastic.co/u/Zaid_Amir)\
**Post date:** [February 15, 2017, 9:46am UTC](https://discuss.elastic.co/t/completion-suggester-suggesting-full-document/75048/3 "2017-02-15T09:46:29Z")

</div>

This is really frustrating and I do not see the need for an auto complete suggester to return an entire document? What was the argument against returning specific field data for an auto complete suggester?

I don't think filtering the source is sufficient since I might have several documents having the same tag. So I might be getting the same suggested tag/element multiple times.

As for the term suggester, I don't see how I can use it as a completion suggester? Well, first I need to apply a query as I do not want to suggest on the entire index.

So that probably leaves me with the Phrase suggester which I am not quite sure how to utilize it as an auto-complete/prefix-based suggester.

Any examples?

---

<div class="post-metadata">

**Author:** ![Zaid\_Amir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zaid_amir/32/54679_2.png) [@Zaid\_Amir](https://discuss.elastic.co/u/Zaid_Amir)\
**Post date:** [February 15, 2017, 10:57am UTC](https://discuss.elastic.co/t/completion-suggester-suggesting-full-document/75048/4 "2017-02-15T10:57:15Z")

</div>

I think I found the solution however it will require the tags to be stored in two separate fields (one to query and the other to aggregate on)

```
{
	"from" : 0,
	"size" : 0,
	"query" : {
		"bool" : {
			"must" : [{
					"term" : {
						"userid" : {
							"value" : 1
						}
					}
				}
			]
		}
	},
	"aggs" : {
		"suggest" : {
			"filter" : {
				"prefix" : {
					"tags" : {
						"value" : "win"
					}
				}
			},
			"aggs" : {
				"Tags_suggest" : {
					"terms" : {
						"field" : "tags_key",
						"size" : 20,
						"include" : {
							"pattern" : "win.*"
						}
					}
				}
			}
		}
	}
}

```

I can live with that, even though it will require twice the storage. And fingers crossed that ES wont remove aggregation filters in the future.

---

<div class="post-metadata">

**Author:** ![Silas\_Hansen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/silas_hansen/32/67521_2.png) [@Silas\_Hansen](https://discuss.elastic.co/u/Silas_Hansen)\
**Post date:** [February 16, 2017, 12:40pm UTC](https://discuss.elastic.co/t/completion-suggester-suggesting-full-document/75048/5 "2017-02-16T12:40:36Z")

</div>

The same for me - It's a shame that it has become document-oriented.

The suggestions I want my users to see might not have anything to do with specific documents. Suggestions could be based on historic queries, shingles or the like. The old suggester gave us a way to get a list of suggestions matching the prefix of the input string - now we only get documents matching and no other near matches if there isn't a document directly linked to it. At least it would have been nice to have a way to keep the old functionality.

I am now forced to go with a terms aggregation with a regex include filter. This means I have no way of providing fuzzy matches now, which is a shame for our solution.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 16, 2017, 12:40pm UTC](https://discuss.elastic.co/t/completion-suggester-suggesting-full-document/75048/6 "2017-03-16T12:40:55Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
