0

I'm using elasticsearch for the first time. I'm trying to use completion suggester in multi-field key, although I don't see any error but I don't get the response.

Mapping creation:

PUT /products5/
{
  "mappings":{
    "products" : {
      "properties" : {
        "name" : {
          "type":"text",
          "fields":{
               "text":{
                    "type":"keyword"
                    },
              "suggest":{  
                  "type" : "completion"
              }
          }
        }
      }
    }

  }
} 

Indexing:

PUT /products5/product/1
{
  "name": "Apple iphone 5"

}
PUT /products5/product/2
{
  "name": "iphone 4 16GB"


}
PUT /products5/product/3
{
  "name": "iphone 3 SS 16GB black"


}
PUT /products5/product/4
{
  "name": "Apple iphone 4 S 16 GB white"


}
PUT /products5/product/5
{ 
  "name": "Apple iphone case"

}

Query:

POST /products5/product/_search
{
  "suggest":{
    "my-suggestion":{
      "prefix":"i",
      "completion":{
        "field":"name.suggest"
      }
    }
  }

}

Output:

   {
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": 0,
    "hits": []
  },
  "suggest": {
    "my-suggestion": [
      {
        "text": "i",
        "offset": 0,
        "length": 1,
        "options": []
      }
    ]
  }
}

Please guide me what is the mistake, I tried every possible options.

rampuriyaaa
  • 4,926
  • 10
  • 34
  • 41

2 Answers2

0

From the first perspective this looks accurate. Probably the reason why you don't have correct response is that you added documents in the index before you created mapping in the index. And documents are not indexed according to the mapping you specified

  • 1
    I believe I've carefully ran each of the commands above. I've added the document after creating index and mapping. – rampuriyaaa Jun 27 '17 at 22:01
0

I have found an issue in your mapping name. There is an inconsistency between name of the mapping and value which you specifies in the url when you're creating new documents. You create a mapping in the index with the name products. And when you add new documents you're specifying product as a name of the mapping of your index and it doesn't end with s. You have a typo.