Completion suggest on empty index returns strange response


(Kirill Teplinskiy) #1

Hello!

Suggest API on ES 2.4.0 returns empty list of suggestions if an index has documents but no documents have matched. However, If an index has no documents then suggestion doesn't appear in the response at all, even the empty list.

Please consider this script:

curl -X PUT 'localhost:9200/music' -d '{
    "mappings": {
        "song" : {
            "properties" : {
                "suggest" : { "type" : "completion" }
            }
        }
    }
}'

curl -X PUT 'localhost:9200/music/song/1?refresh=true' -d '{
    "suggest" : {
        "input": [ "Nevermind", "Nirvana" ],
        "output": "Nirvana - Nevermind"
    }
}'

curl -X POST 'localhost:9200/music/_suggest?pretty' -d '{
    "song-suggest" : {
        "text" : "z",
        "completion" : {
            "field" : "suggest"
        }
    }
}'

The response to the last request is:

{
  "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "song-suggest": [
    {
      "text": "z",
      "offset": 0,
      "length": 1,
      "options": []
    }
  ]
}

If we will not index a document the response will be different:

curl -X PUT 'localhost:9200/music' -d '{
    "mappings": {
        "song" : {
            "properties" : {
                "suggest" : { "type" : "completion" }
            }
        }
    }
}'

curl -X POST 'localhost:9200/music/_suggest?pretty' -d '{
    "song-suggest" : {
        "text" : "z",
        "completion" : {
            "field" : "suggest"
        }
    }
}'

The response is:

{
  "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
  }
}

The response doesn't have song-suggest field. It looks inconsistent for me. Shouldn't these two cases return the same response with empty list of suggestions?


(system) #2