elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
69.98k stars 24.75k forks source link

Context Suggester does not return completed answers. #107597

Open vietnguyengit opened 6 months ago

vietnguyengit commented 6 months ago

Description

Hi all,

I tried the completion suggester and I was able to get all the potential results I want, but the completion suggester will check against all documents in the index, while I do want to add some filters to have more relevant suggestions;

therefore I have to switch to use the context suggester, but this suggester doesn't give me the expecting results. For example (copied pretty much the same from your official documentation)

# create the mappings context
PUT place
{
  "mappings": {
    "properties": {
      "suggest": {
        "type": "completion",
        "contexts": [
          {                                 
            "name": "place_type",
            "type": "category"
          }
        ]
      }
    }
  }
}

# add something
PUT place/_doc/1
{
  "suggest": {
    "input": [ "timmy's", "starbucks", "dunkin donuts" ],
    "contexts": {
      "place_type": [ "cafe", "food" ]                    
    }
  }
}

PUT place/_doc/2
{
  "suggest": {
    "input": [ "tim", "timmer", "timber"],
    "contexts": {
      "place_type": [ "wood" ]                    
    }
  }
}

# time to check for the response
POST place/_search?pretty
{
  "suggest": {
    "place_suggestion": {
      "prefix": "ti",
      "completion": {
        "field": "suggest",
        "size": 10,
        "contexts": {
          "place_type": [ "wood", "cafe" ]
        }
      }
    }
  }
}

my expecting results when providing ti are these suggestions:

"tim", "timmer", "timber", ""timmy's"

however, I could only get 2 "tim", "timmy's"

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 0,
      "relation": "eq"
    },
    "max_score": null,
    "hits": []
  },
  "suggest": {
    "place_suggestion": [
      {
        "text": "ti",
        "offset": 0,
        "length": 2,
        "options": [
          {
            "text": "tim",
            "_index": "place",
            "_id": "2",
            "_score": 1,
            "_source": {
              "suggest": {
                "input": [
                  "tim",
                  "timmer",
                  "timber"
                ],
                "contexts": {
                  "place_type": [
                    "wood"
                  ]
                }
              }
            },
            "contexts": {
              "place_type": [
                "wood"
              ]
            }
          },
          {
            "text": "timmy's",
            "_index": "place",
            "_id": "1",
            "_score": 1,
            "_source": {
              "suggest": {
                "input": [
                  "timmy's",
                  "starbucks",
                  "dunkin donuts"
                ],
                "contexts": {
                  "place_type": [
                    "cafe",
                    "food"
                  ]
                }
              }
            },
            "contexts": {
              "place_type": [
                "cafe"
              ]
            }
          }
        ]
      }
    ]
  }
}

why is that? and how can I get something similar to when using completion suggestion with the results filtered against a particular subset. Or should you be considered to have such feature if it does not exist yet.

Thank you all.

elasticsearchmachine commented 6 months ago

Pinging @elastic/es-search (Team:Search)

elasticsearchmachine commented 3 months ago

Pinging @elastic/es-search-relevance (Team:Search Relevance)