# How to create a completion suggester index without duplicates?

**URL:** <https://discuss.elastic.co/t/how-to-create-a-completion-suggester-index-without-duplicates/151469>\
**Category:** Elasticsearch\
**Created:** [October 8, 2018, 2:00pm UTC](https://discuss.elastic.co/t/how-to-create-a-completion-suggester-index-without-duplicates/151469 "2018-10-08T14:00:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thurse](https://avatars.discourse-cdn.com/v4/letter/t/8e8cbc/32.png) [@thurse](https://discuss.elastic.co/u/thurse)\
**Post date:** [October 8, 2018, 2:00pm UTC](https://discuss.elastic.co/t/how-to-create-a-completion-suggester-index-without-duplicates/151469/1 "2018-10-08T14:00:15Z")

</div>

Hi,

I want to organize a simple index of various search terms which gets updated frequently by the users of my search api. For this purpose I created the following mapping

```
{
    "mappings": {
    "_doc" : {
        "properties" : {
            "term" : {
                "type" : "completion",
                "analyzer": "simple",
	            "fields": {
			        "length": {
		                 "type": "token_count",
              	         "analyzer": "standard"
                         }
	               }
            }
        }
    }
  }
}

```

and these test documents:

```
{
    "term": "test"
}

{
    "term": "wiki test"
}

{
    "term": "fast wiki test"
}

```

My problems are revolving around the issue that by my definition a duplicate is present whenever the term field consist of the _exact_ same tokens, so in the example above I have three distinct documents. This is the reason I added the token\_count field in the mapping.

Unfortunately if I want to search with

```
{ 
"suggest": {
	"querysuggest": {
		"prefix": "test",
		"completion" : {
			"field": "term"
		}
	}
}
}

```

I dont see a way to add the term.length filter. Plus- _prefix_ works only well if i use the input-field at indexing time but this crashes my token\_count mapping:

```
{
"term" : {
	"input" : ["superfast", "wiki"]
}
}

```

Resulting this error:

```
{
"error": {
	"root_cause": [
		{
			"type": "mapper_parsing_exception",
			"reason": "failed to parse [term.length]"
		}
	],
	"type": "mapper_parsing_exception",
	"reason": "failed to parse [term.length]",
	"caused_by": {
		"type": "illegal_state_exception",
		"reason": "Can't get text on a END_OBJECT at 4:2"
	}
},
"status": 400
 }

```

So what can I do to get a search term index which only holds unique sets of tokens / string arrays?

Regards,

thurse

---

<div class="post-metadata">

**Author:** ![thurse](https://avatars.discourse-cdn.com/v4/letter/t/8e8cbc/32.png) [@thurse](https://discuss.elastic.co/u/thurse)\
**Post date:** [October 9, 2018, 9:19am UTC](https://discuss.elastic.co/t/how-to-create-a-completion-suggester-index-without-duplicates/151469/2 "2018-10-09T09:19:49Z")

</div>

Figured it out myself, the point is to use the keyword field just as in the documentation ([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)). Now I can search for duplicates via keyword and a term-query but still get the suggestions from the completion field. The only problem is that the order of the search terms still matters, but thats a thing i can live with for now.

Regards,

thurse

---

<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:** [November 6, 2018, 9:19am UTC](https://discuss.elastic.co/t/how-to-create-a-completion-suggester-index-without-duplicates/151469/3 "2018-11-06T09:19:53Z")

</div>

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