Search code examples
c#nestelasticsearch-6

Combining Elastic Search completion suggester with IBoolQuery in Nest


I have tried to filter my documents based on certain exclusions before invoking the completion suggester.

 var response = Client.Search<Suggestion>(s => s  
          .Query(q => q.Bool(MustNot(m => m.SpanTerm(st => st.Field("foo").Value("bar"))))     
          .Suggest(su => su
                .Completion("title", cs => cs
                    .Field(f => f.TitleSuggest)
                    .Prefix(searchText)                        .
                    )
                    .Size(10)
                )
            )

        );

But this doesn't seem to work. The same result set is returned.


Solution

  • After further reading, this doesn't seem possible using standard bool operators. Context suggesters are the solution, however this doesn't support e.g. MustNot modifiers

    https://www.elastic.co/guide/en/elasticsearch/reference/current/suggester-context.html