# How to configure and query multiple context suggesters in 5.0

**URL:** <https://discuss.elastic.co/t/how-to-configure-and-query-multiple-context-suggesters-in-5-0/64659>\
**Category:** Elasticsearch\
**Created:** [November 2, 2016, 3:42am UTC](https://discuss.elastic.co/t/how-to-configure-and-query-multiple-context-suggesters-in-5-0/64659 "2016-11-02T03:42:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kabcampbell](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kabcampbell/32/137695_2.png) [@kabcampbell](https://discuss.elastic.co/u/kabcampbell)\
**Post date:** [November 2, 2016, 3:42am UTC](https://discuss.elastic.co/t/how-to-configure-and-query-multiple-context-suggesters-in-5-0/64659/1 "2016-11-02T03:42:20Z")

</div>

I have set up my completion suggester with the following contexts:

> ```
> > "suggest": {
> > "type": "completion",
> > "contexts": [
> > {
> > "name": "companyContext",
> > "type": "category"
> > },
> > {
> > "name": "usersContext", 
> > "type": "category"
> > }                     
> > ]
> > }
> 
> ```

I've indexed a document with the following values in those context fields:

> ```
> > "suggest": {
> > "input": "test team site",
> > "contexts": {
> > "companyContext": "vendor"
> > "usersContext": ["chad", "fred"],
> >             
> > }        
> > }
> 
> ```

I would like to retrieve suggestions where both the companyContext is a match and the usersContext is a match. I was able to do this in version 2.x. But now if I run the suggestions query as follows:

> ```
> > "suggestions": {
> > "text": "tes",
> > "completion": {
> > "field": "suggest",
> > "contexts": {
> > "companyContext": "vendor",
> > "usersContext": "joe"                
> > }            
> > }
> > }
> 
> ```

I get the document back even though the usersContext is not a match. This was not the case in 2.x. Did something change in 5.0 or am I just getting the syntax wrong?

---

<div class="post-metadata">

**Author:** ![Robooto](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robooto/32/14122_2.png) [@Robooto](https://discuss.elastic.co/u/Robooto)\
**Post date:** [December 23, 2016, 7:35pm UTC](https://discuss.elastic.co/t/how-to-configure-and-query-multiple-context-suggesters-in-5-0/64659/2 "2016-12-23T19:35:18Z")

</div>

I'm having the same issue and wondering if you ever found a resolution to this issue.

Example

```
 PUT place
{
    "mappings": {
        "shops" : {
            "properties" : {
                "suggest" : {
                    "type" : "completion",
                    "contexts": [
                        { 
                            "name": "place_type",
                            "type": "category",
                            "path": "cat"
                        },
                        { 
                            "name": "locationID",
                            "type": "category",
                            "path": "locID"
                        }
                    ]
                }
            }
        }
    }
}

PUT place/shops/1
{
    "suggest": ["timmy's", "starbucks", "dunkin donuts"],
    "cat": ["cafe", "food"],
    "locID": "20"
}

POST place/_suggest?pretty
{
    "suggest" : {
        "prefix" : "tim",
        "completion" : {
            "field" : "suggest",
            "size": 10,
            "contexts": {
                "place_type": ["restaurants"],
                "locationID": ["20"]
            }
        }
    }
}

```

I would expect this search to have no results since I am filtering by LocationID of 20 and place\_type of restaurants but it seems to just match one or the other.

Is there a syntax I am missing to filter by both contexts?

---

<div class="post-metadata">

**Author:** ![kabcampbell](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kabcampbell/32/137695_2.png) [@kabcampbell](https://discuss.elastic.co/u/kabcampbell)\
**Post date:** [December 24, 2016, 9:53pm UTC](https://discuss.elastic.co/t/how-to-configure-and-query-multiple-context-suggesters-in-5-0/64659/3 "2016-12-24T21:53:15Z")

</div>

I have not. I submitted this as an issue on Github which it looks like you found: [https://github.com/elastic/elasticsearch/issues/21291#issuecomment-258380703](https://github.com/elastic/elasticsearch/issues/21291#issuecomment-258380703)

Until that update is in place, I'm keeping my production application on 2.x, since I can't figure out a workaround.

---

<div class="post-metadata">

**Author:** ![cara-dev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cara-dev/32/17463_2.png) [@cara-dev](https://discuss.elastic.co/u/cara-dev)\
**Post date:** [April 18, 2017, 3:48pm UTC](https://discuss.elastic.co/t/how-to-configure-and-query-multiple-context-suggesters-in-5-0/64659/4 "2017-04-18T15:48:25Z")

</div>

Has there been any update to this or has anyone found a workaround? This is currently a show stopper for our upgrade from version 2.3 to 5.3. Thanks in advance.

---

<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:** [July 5, 2017, 10:01pm UTC](https://discuss.elastic.co/t/how-to-configure-and-query-multiple-context-suggesters-in-5-0/64659/5 "2017-07-05T22:01:04Z")

</div>


