# Completion Suggester ignores Length Token Filter

**URL:** https://discuss.elastic.co/t/completion-suggester-ignores-length-token-filter/51971
**Category:** Elasticsearch
**Created:** [June 6, 2016, 3:18pm UTC](https://discuss.elastic.co/t/completion-suggester-ignores-length-token-filter/51971 "2016-06-06T15:18:31Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![cech](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cech/32/10171_2.png) [@cech](https://discuss.elastic.co/u/cech)
#### Post date: [June 6, 2016, 3:18pm UTC](https://discuss.elastic.co/t/completion-suggester-ignores-length-token-filter/51971/1 "2016-06-06T15:18:31Z")

</div>

I'm trying to create an autosuggest feature with the completion type and i would like to filter the input with the length token filter (to limit the input to entries that are at least X characters long). Sadly, it seems that the analyzer value of the suggest-field is completely ignoring the token filters I set for the suggest field, both when indexing and when suggesting... Here's my test-setup:

Creating the index:

```
curl -XPUT "http://localhost:9200/test_index/" -d'
{
   "settings": {
      "number_of_shards": 1,
      "number_of_replicas": 0,
      "analysis": { 
         "filter": {
            "length_gt": {
               "type": "length",
               "min": 10
            }
         },
         "analyzer": {
            "suggestions": {
               "type": "custom",
               "tokenizer": "lowercase",
               "filter": [
                  "length_gt"
               ]
            }
         }
      }
   },
   "mappings": {
      "product": {
         "properties": {
            "description": {
               "type": "string"
            },
            "tags": {
               "type": "string"
            },
            "title": {
               "type": "string"
            },
            "tag_suggest": {
               "type": "completion",
               "analyzer": "suggestions",
               "search_analyzer": "suggestions",
               "payloads": false
            }
         }
      }
   }
}'

```

Indexing two Documents:

```
curl -XPUT "http://localhost:9200/test_index/product/1" -d'{
   "title": "Product1",
   "description": "Product1 Description",
   "tags": [
      "blog",
      "magazine",
      "responsive",
      "two columns",
      "wordpress"
   ],
   "tag_suggest": {
      "input": [
         "blog",
         "magazine",
         "responsive",
         "two columns",
         "wordpress"
      ]
   }
}'
curl -XPUT "http://localhost:9200/test_index/product/2" -d'
{
    "title": "Product2",
    "description": "Product2 Description",
    "tags": [
        "blog",
        "paypal",
        "responsive",
        "skrill",
        "wordland"
    ],
   "tag_suggest": {
      "input": [
         "blog",
        "paypal",
        "responsive",
        "skrill",
        "wordland"
      ]
   }
}'

```

Inspecting the index content:

```
curl -XPOST "http://localhost:9200/test_index/_search"
{"took":1,"timed_out":false,"_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":1,"max_score":1.0,"hits":[{"_index":"test_index","_type":"product","_id":"1","_score":1.0,"_source":{
   "title": "Product1",
   "description": "Product1 Description",
   "tags": [
      "blog",
      "magazine",
      "responsive",
      "two columns",
      "wordpress"
   ],
   "tag_suggest": {
      "input": [
         "blog",
         "magazine",
         "responsive",
         "two columns",
         "wordpress"
      ]
   }
}}]}}

```

EDIT:

Just be sure that the analyzer itself works, I tried to analyze some text with my 'suggestions' analyzer directly:

```
curl -XGET 'localhost:9200/test_index/_analyze' -d '
{
  "analyzer" : "suggestions",
  "text" : ["all this should be removed because it is too short", "the looooooooooooong words are the oooooooooooonly thing left"]
}'

```

which worked fine:

```auto
{
    "tokens": [
        {
            "end_offset": 71, 
            "position": 111, 
            "start_offset": 55, 
            "token": "looooooooooooong", 
            "type": "word"
        }, 
        {
            "end_offset": 101, 
            "position": 115, 
            "start_offset": 86, 
            "token": "oooooooooooonly", 
            "type": "word"
        }
    ]
}

```

Is there any reason why this wouldn't work? I have tried the stopwords filter as well, it is also ignored. It seems to me as if this is simply a bug in ES - but IMHO this _should_ work, since there are even specific settings for the completion field to define both the (indexing) analyzer _and_ the query analyzer to use. I'm getting really desperate here - anybody have any idea why this is happening?

---

<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: [July 5, 2017, 10:45pm UTC](https://discuss.elastic.co/t/completion-suggester-ignores-length-token-filter/51971/2 "2017-07-05T22:45:38Z")

</div>


