# How to add contexts to Suggestion Builder in java

**URL:** <https://discuss.elastic.co/t/how-to-add-contexts-to-suggestion-builder-in-java/178595>\
**Category:** Elasticsearch\
**Created:** [April 26, 2019, 8:58am UTC](https://discuss.elastic.co/t/how-to-add-contexts-to-suggestion-builder-in-java/178595 "2019-04-26T08:58:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pkaul](https://avatars.discourse-cdn.com/v4/letter/p/8dc957/32.png) [@pkaul](https://discuss.elastic.co/u/pkaul)\
**Post date:** [April 26, 2019, 8:58am UTC](https://discuss.elastic.co/t/how-to-add-contexts-to-suggestion-builder-in-java/178595/1 "2019-04-26T08:58:04Z")

</div>

```
SuggestionBuilder suggestionBuilder = SuggestBuilders.completionSuggestion("suggest").prefix("test").contexts(Collections.singletonMap("cat", Collections.singletonList(CategoryQueryContext.builder().setCategory("cat0").build())));
			SuggestBuilder suggestBuilder = new SuggestBuilder();
			suggestBuilder.addSuggestion("test123", suggestionBuilder);
			
			SearchRequest searchRequest = new SearchRequest("test");
			SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
			searchSourceBuilder.suggest(suggestBuilder);
			searchRequest.source(searchSourceBuilder);
			
			SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);`Preformatted text`

```

In the above code, the contexts method does not let me pass the argument as above. It says : The method contexts(Map\<String,List\<? extends ToXContent\>\>) in the type CompletionSuggestionBuilder is not applicable for the arguments (Map\<String,List\<  
CategoryQueryContext\>\>)

Is there a different way to add context in the SuggestionBuilder in java?  
I am using elastic 7.

---

<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:** [May 24, 2019, 8:58am UTC](https://discuss.elastic.co/t/how-to-add-contexts-to-suggestion-builder-in-java/178595/2 "2019-05-24T08:58:09Z")

</div>

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