setTypes ignored on Completion search


(Bendg25) #1

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?


(Alexander Reelsen) #2

Hey,

yes, the completion suggester takes the whole index into account.

You can however use the context suggester to filter for documents in an index (also allowing the for the type)

--Alex


(system) #3

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