# Match\_phrase query does not work when using context suggestions

**URL:** <https://discuss.elastic.co/t/match-phrase-query-does-not-work-when-using-context-suggestions/158030>\
**Category:** Elasticsearch\
**Created:** [November 23, 2018, 2:58pm UTC](https://discuss.elastic.co/t/match-phrase-query-does-not-work-when-using-context-suggestions/158030 "2018-11-23T14:58:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diyarbakir](https://avatars.discourse-cdn.com/v4/letter/d/bbce88/32.png) [@Diyarbakir](https://discuss.elastic.co/u/Diyarbakir)\
**Post date:** [November 23, 2018, 2:58pm UTC](https://discuss.elastic.co/t/match-phrase-query-does-not-work-when-using-context-suggestions/158030/1 "2018-11-23T14:58:10Z")

</div>

Hi,

I am using ES version 5.6.2

We are using an index to store and retrieve our own list of suggestions. We use a match\_phrase query to find a specific suggestion and get it's ID. This works fine until we start adding contexts to our suggestion mapping. Somehow, match\_phrase does not yield any results in combination with the contexts. I have added the steps to recreate to problem below.

Note: I do not need to search for suggestions, as in, I sent a query for "foot" and it suggests "football" as a result. This is not my problem. My problem is that I want to get the ID for a suggestion that has been indexed.

**Create a test index:**

```
{  
   "template":"index_suggest_test*",
   "settings":{  
      "number_of_shards":1,
      "number_of_replicas":2
   },
   "mappings":{  
      "suggester":{  
         "_meta":{  
            "version":"1.1.0"
         },
         "properties":{  
            "suggest":{  
               "type":"completion",
               "analyzer":"whitespace"
               ]
            },
            "modified_at":{  
               "type":"date"
            }
        }
      }
   }
}

```

**Insert a suggestion:**

```
{  
   "suggest":{  
      "input":[  
         "my suggestion"
      ],
      "weight":100
   },
   "modified_at":"2018-11-20T15:15:00.000Z"
}

```

**Search for a specific suggestion: THIS WORKS**

```
{
    "query": {
        "match_phrase" : { "suggest" : "my suggestion" }
    }
}

```

_And with contexts it is not working:_

**Create a test index WITH CONTEXTS:**

```
{  
   "template":"index_suggest_test*",
   "settings":{  
      "number_of_shards":1,
      "number_of_replicas":2
   },
   "mappings":{  
      "suggester":{  
         "_meta":{  
            "version":"1.1.0"
         },
         "properties":{  
            "suggest":{  
               "type":"completion",
               "analyzer":"whitespace",
               "contexts":[  
                  {  
                     "name":"suggest_type",
                     "type":"category"
                  }
               ]
            },
            "modified_at":{  
               "type":"date"
            }
        }
      }
   }
}

```

**Insert a suggestion:**

```
{  
   "suggest":{  
      "input":[  
         "my suggestion"
      ],
      "weight":100,
      "contexts": {
      	"suggest_type" : ["top"]
      }
   },
   "modified_at":"2018-11-20T15:15:00.000Z"
}

```

**Search for a specific suggestion: THIS DOES NOT WORK**

```
{
    "query": {
        "match_phrase" : { "suggest" : "my suggestion" }
    }
}
```

---

<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, 2018, 2:58pm UTC](https://discuss.elastic.co/t/match-phrase-query-does-not-work-when-using-context-suggestions/158030/2 "2018-12-21T14:58:17Z")

</div>

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