Implementing Suggestion Completion with multiple words

I am using the suggestion api within ES with completion. My implementation works (code below) but I would like to search for multiple words within a query. In the example below if I query search "word" it finds "wordpress" and outputs "Found". What I am am trying to accomplish is querying with something like "word blog magazine" which are all tags and when searched it will output "Found". Any help would be appreciated!

Mapping:

curl -XPUT "http://localhost:9200/test_index/" -d'
    {
   "mappings": {
      "product": {
         "properties": {
            "description": {
               "type": "string"
            },
            "tags": {
               "type": "string"
            },
            "title": {
               "type": "string"
            },
            "tag_suggest": {
               "type": "completion",
               "index_analyzer": "simple",
               "search_analyzer": "simple",
               "payloads": false
            }
         }
      }
   }
}'

Add Document:

curl -XPUT "http://localhost:9200/test_index/product/1" -d'
    {
   "title": "Product1",
   "description": "Product1 Description",
   "tags": [
      "blog",
      "magazine",
      "responsive",
      "two columns",
      "wordpress"
   ],
   "tag_suggest": {
      "input": [
         "blog",
         "magazine",
         "responsive",
         "two columns",
         "wordpress"
      ],
      "output": "Found"
   }
}'

_Suggest query

curl -XPOST "http://localhost:9200/test_index/_suggest" -d'
    {
    "product_suggest":{
        "text":"word",
        "completion": {
            "field" : "tag_suggest"
        }
    }
}'
The results are as we would expect:
    {
    "_shards": {
      "total": 1,
      "successful": 1,
      "failed": 0
   },
   "product_suggest": [
      {
         "text": "word",
         "offset": 0,
         "length": 4,
         "options": [
            {
           "text": "Found",
           "score": 1
        },
         ]
      }
   ]
}
1 Like