# setTypes ignored on Completion search

**URL:** <https://discuss.elastic.co/t/settypes-ignored-on-completion-search/74104>\
**Category:** Elasticsearch\
**Created:** [February 6, 2017, 6:07pm UTC](https://discuss.elastic.co/t/settypes-ignored-on-completion-search/74104 "2017-02-06T18:07:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bendg25](https://avatars.discourse-cdn.com/v4/letter/b/57b2e6/32.png) [@bendg25](https://discuss.elastic.co/u/bendg25)\
**Post date:** [February 6, 2017, 6:07pm UTC](https://discuss.elastic.co/t/settypes-ignored-on-completion-search/74104/1 "2017-02-06T18:07:34Z")

</div>

Hi

Here is my code:

CompletionSuggestionBuilder completionSuggestionBuilder = SuggestBuilders.completionSuggestion("suggest");

```
    if (isEmpty(searchString)) {
        LOG.info("Adding regex");
        completionSuggestionBuilder.regex(".");
    } else {
        LOG.info("Adding search string as prefix");
        completionSuggestionBuilder.prefix(searchString);
    }

    SuggestBuilder suggest = new SuggestBuilder().addSuggestion(suggestionName, completionSuggestionBuilder);

    LOG.info("Suggest search on Index [" + INDEX_NAME + "] and types set to [" + resourceDefinitionId.getId() + "]");

    SearchRequestBuilder searchRequestBuilder = transportClient.prepareSearch(INDEX_NAME).setTypes("myId").suggest(suggest);

    LOG.info("searchRequestBuilder is " + searchRequestBuilder.toString());

    SearchResponse searchResponse = searchRequestBuilder.get();
    
    SearchHits hits = searchResponse.getHits();

```

But I get hits back that are not of the supplied type. Is this expected behaviour?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 7, 2017, 8:00am UTC](https://discuss.elastic.co/t/settypes-ignored-on-completion-search/74104/2 "2017-02-07T08:00:57Z")

</div>

Hey,

yes, the [completion suggester takes the whole index into account](https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-suggesters-completion.html).

You can however use the [context suggester](https://www.elastic.co/guide/en/elasticsearch/reference/5.2/suggester-context.html) to filter for documents in an index (also allowing the for the type)

--Alex

---

<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 7, 2017, 8:01am UTC](https://discuss.elastic.co/t/settypes-ignored-on-completion-search/74104/3 "2017-03-07T08:01:01Z")

</div>

Closed on March 7, 2017, 8:01am UTC

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