elastic/elasticsearch

Completion Suggester for doc with multiple matching inputs only returns one suggestion

Open

#31,738 opened on Jul 2, 2018

View on GitHub
 (13 comments) (4 reactions) (0 assignees)Java (25,882 forks)batch import
:Search Relevance/Suggesters>enhancementTeam:Search Relevancehelp wanted

Repository metrics

Stars
 (76,700 stars)
PR merge metrics
 (Avg merge 2d) (1,000 merged PRs in 30d)

Description

Elasticsearch version 6.3.0 (Also tested on 6.2.4)

Plugins installed: []

JVM version (java -version): OpenJdk 1.8.0_161 (also tested Oracle jvm 1.8.0_171)

OS version (uname -a if on a Unix-like system): Linux 4.4.115-k8s (FYI also tested on unsupported windows 10)

Description of the problem including expected versus actual behavior: Completion Suggester A document can have multiple "input" for the completion suggester. A search can made with a prefix that matches more than one suggestion.

  • EXPECTED: the suggestion array ("song-suggest" in the example) should return the same "_source" document multiple times, each with different options.text.

Expected response { "took" : 25, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 0, "max_score" : 0.0, "hits" : [ ] }, "suggest" : { "song-suggest" : [ { "text" : "n", "offset" : 0, "length" : 1, "options" : [ { "text" : "Nevermind", "_index" : "music", "_type" : "_doc", "_id" : "1", "_score" : 34.0, "_source" : { "suggest" : { "input" : [ "Nevermind", "Nirvana" ], "weight" : 34 } } }, { "text" : "n", "offset" : 0, "length" : 1, "options" : [ { "text" : "Nirvana", "_index" : "music", "_type" : "_doc", "_id" : "1", "_score" : 34.0, "_source" : { "suggest" : { "input" : [ "Nevermind", "Nirvana" ], "weight" : 34 } } } ] } ] } }

  • ACTUAL: the suggestion array only contains one suggestion per indexed document even if more that one input matches

Actual response received { "took" : 25, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 0, "max_score" : 0.0, "hits" : [ ] }, "suggest" : { "song-suggest" : [ { "text" : "n", "offset" : 0, "length" : 1, "options" : [ { "text" : "Nevermind", "_index" : "music", "_type" : "_doc", "_id" : "1", "_score" : 34.0, "_source" : { "suggest" : { "input" : [ "Nevermind", "Nirvana" ], "weight" : 34 } } } ] } ] } }

Steps to reproduce:

Based on the example here https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html

  1. Create mappings curl -X PUT "localhost:9200/music" -H 'Content-Type: application/json' -d' { "mappings": { "_doc" : { "properties" : { "suggest" : { "type" : "completion" }, "title" : { "type": "keyword" } } } } } '
  2. Index document curl -X PUT "localhost:9200/music/_doc/1?refresh" -H 'Content-Type: application/json' -d' { "suggest" : { "input": [ "Nevermind", "Nirvana" ], "weight" : 34 } } '
  3. Search with prefix 'N' curl -X POST "localhost:9200/music/_search?pretty" -H 'Content-Type: application/json' -d' { "suggest": { "song-suggest" : { "prefix" : "n", "completion" : { "field" : "suggest" } } } } '

Contributor guide