How to configure and query multiple context suggesters in 5.0

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?

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?

1 Like

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

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

1 Like

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.