eugene
eugene

Reputation: 41785

Elasticsearch, understanding completion suggester

I got the completion suggest working for autocomplete

However I have a question that I can't answer myself

Why are we storing the suggest in a field of the document?

GET /my_index/_search

{
  hits: [{
    "_id": 1,
    "suggest": {
      "input": [
        "p1",
        "p22",
      ],
      "weight": 1
    }
  }, {
    "_id": 2,
    "suggest": {
      "input": [
        "p22",
        "p3",
      ],
      "weight": 1
    }
  }]
}

For autocomplete, don't we just need a list of phrases?

[
  "p1",
  "p22",
  "p3"
]
  1. What do we gain by the association of suggest and the doc?
  2. as in example, multiple docs can have same suggest input , p22 in the example. When I ask for autocomplete for p2 I get two p22. is there a way of handling this?

Upvotes: 0

Views: 93

Answers (1)

Val
Val

Reputation: 217594

  1. There's no other way to store suggestions than storing them in a completion field inside the document itself. This gives you maximum flexibility, because even if two documents have the same or similar suggestions, you can give one a higher weight than the other if you deem necessary.

  2. If you have multiple documents with the same suggestions, you can leverage the skip_duplicates setting and ES will filter out duplicate suggestions from the response.

Upvotes: 1

Related Questions