Match_phrase query does not work when using context suggestions

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" }
    }
}

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