# Suggester Context

**URL:** <https://discuss.elastic.co/t/suggester-context/125587>\
**Category:** Elasticsearch\
**Created:** [March 26, 2018, 10:52am UTC](https://discuss.elastic.co/t/suggester-context/125587 "2018-03-26T10:52:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![han1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/han1/32/20141_2.png) [@han1](https://discuss.elastic.co/u/han1)\
**Post date:** [March 26, 2018, 10:52am UTC](https://discuss.elastic.co/t/suggester-context/125587/1 "2018-03-26T10:52:42Z")

</div>

Hi  
We have an index that uses an Autocomplete Suggester. The index definition is:

.Completion(c =\> c.Analyzer("standard")  
.PreserveSeparators(true)  
.MaxInputLength(100)  
.Contexts(ctx=\> ctx  
.Category(x=\>x.Name("country").Path(p=\>p.Country))  
.Category(x =\> x.Name("flags").Path(p =\> p.AvailableCategories))  
)  
.Name("localitySuggestions")  
)

As you can see we have 2 category contexts.

When querying for example:

var searchResponse = await client.SearchAsync(s =\> s  
.Size(MAX\_SUGGESTIONS)  
.Source(sf =\> sf.Excludes(e =\> e.Field("geometry")))  
//.Query(q =\> q  
//.Bool(bq =\> bq.Filter(filters)))  
.Suggest(ss =\> ss  
.Completion("suggestions", c =\> c  
.Field("localitySuggestions")  
.Prefix(prefix)  
.Contexts(ctxs=\>ctxs.Context("flags", ctx =\> ctx.Context(flags)).Context("country", ctx =\> ctx.Context(country)))

```
                    )
                ).Index("localities")
            );

```

Elasticsearch uses an OR operation. i.e. it will return results if either is true.

Is there any way to make the operation an AND i.e.BOTH contexts must be true in order for the document to be matched?

Many thanks

---

<div class="post-metadata">

**Author:** ![jimczi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimczi/32/47985_2.png) [@jimczi](https://discuss.elastic.co/u/jimczi)\
**Post date:** [March 30, 2018, 1:37pm UTC](https://discuss.elastic.co/t/suggester-context/125587/2 "2018-03-30T13:37:25Z")

</div>

No that's not possible. The contexts are additive, you can boost values that have multiple contexts (by adding more context values to your query) but you cannot enforce an AND between the context values. If you want to only match suggestions with multiple contexts you can create a composite contexts `flags-and-country` and set the context values at index time as the combinations of all flags and countries for the document.

---

<div class="post-metadata">

**Author:** ![han1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/han1/32/20141_2.png) [@han1](https://discuss.elastic.co/u/han1)\
**Post date:** [March 30, 2018, 7:33pm UTC](https://discuss.elastic.co/t/suggester-context/125587/3 "2018-03-30T19:33:03Z")

</div>

Many Thanks.

We already did that but wondered if the AND was a possibility.

---

<div class="post-metadata">

**Author:** ![han1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/han1/32/20141_2.png) [@han1](https://discuss.elastic.co/u/han1)\
**Post date:** [March 30, 2018, 7:39pm UTC](https://discuss.elastic.co/t/suggester-context/125587/4 "2018-03-30T19:39:56Z")

</div>

Many Thanks.

We already did that but wondered if that was a possibility.

Regards

Hassan

---

<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:** [April 27, 2018, 7:40pm UTC](https://discuss.elastic.co/t/suggester-context/125587/5 "2018-04-27T19:40:05Z")

</div>

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