# Using CompletionSuggestionBuilder with context in Java

**URL:** <https://discuss.elastic.co/t/using-completionsuggestionbuilder-with-context-in-java/67015>\
**Category:** Elasticsearch\
**Created:** [November 23, 2016, 4:49pm UTC](https://discuss.elastic.co/t/using-completionsuggestionbuilder-with-context-in-java/67015 "2016-11-23T16:49:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cosmin\_Marginean1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cosmin_marginean1/32/75703_2.png) [@Cosmin\_Marginean1](https://discuss.elastic.co/u/Cosmin_Marginean1)\
**Post date:** [November 23, 2016, 4:49pm UTC](https://discuss.elastic.co/t/using-completionsuggestionbuilder-with-context-in-java/67015/1 "2016-11-23T16:49:00Z")

</div>

Hi guys

I'm trying to use the CompletionSuggestionBuilder (context suggester) with the Java client (ES 5.0.1), and I'm struggling with adding contexts, and the API is not entirely clear on that.

This is as far as I got, but again, only by intuitively surfing the API, not really sure if this is the right way to go about it, as documentation is scarce in this area.

```
CompletionSuggestionBuilder completion = new CompletionSuggestionBuilder(FIELD_SUGGEST)
        .prefix(text);
Map<String, List<? extends ToXContent>> contexts = new HashMap<>();
    
???
    
completion.contexts(contexts);

```

Also, methods on CompletionSuggestionBuilder.Contexts2x seem to be all deprecated, which I presume is not the route to pursue.

Thanks  
Cos

---

<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:** [December 21, 2016, 4:49pm UTC](https://discuss.elastic.co/t/using-completionsuggestionbuilder-with-context-in-java/67015/2 "2016-12-21T16:49:28Z")

</div>

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