0

My DOc is below

[
{'id':1, 'name': 'sachin messi', 'description': 'football@football.com', 'type': 'football', 'var':'sports'},
{'id':2, 'name': 'lionel messi', 'description': 'messi@fifa.com','type': 'soccer','var':'sports'},
{'id':3, 'name': 'sachin', 'description': 'was', 'type': 'cricket', 'var':'sports'}
]
  • I need to suggest a string which after the term

My DSL query is below

quer = {
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "var.keyword": [
              "notsports"
            ]
          }
        },
        {
          "query_string": {
            "query": "schin",
            "fields": [
              "name^128",
              "description^64",
            ]
          }
        }
      ]
    }
  },
  "suggest": {
    "my-suggestion": {
      "text": "schin",
      "term": {
        "field": "name",
        "prefix_length": 0,
        "min_word_length": 3,
        "string_distance": "ngram"
      }
    }
  }
}
  • My var.keyword is notsports

  • still i am getting suggestion 'suggest': {'my-suggestion': [{'text':'schin','offset':0,'length':5,'options': [{'text':'sachin', 'score': 0.75, 'freq': 1}]}

  • When i tried to put suggest inside terms list then i am getting RequestError: RequestError(400, 'x_content_parse_exception', 'unknown query [suggest]')

  • I need to get the suggestion only if var.keyword matches sports

I have asked question in elasticsearch also https://discuss.elastic.co/t/how-to-add-suggestion-inside-term-query-in-dsl/309893

sim
  • 524
  • 3
  • 14
  • it seems like it not possible to restricts it and same is mentioned [here](https://stackoverflow.com/questions/45009239/how-to-run-elasticsearch-completion-suggester-query-on-limited-set-of-documents) in another SO question. You can use Context Suggestor but not sure of it is fit for your usecase or not. – Sagar Patel Jul 13 '22 at 13:35
  • @SagarPatel then is there any way to suggest the text if var.keyword matches sports – sim Jul 14 '22 at 05:20
  • as far as i know not possible but you can do some research on it. – Sagar Patel Jul 14 '22 at 07:28
  • @SagarPatel i have asked question in elasticsearch also https://discuss.elastic.co/t/how-to-add-suggestion-inside-term-query-in-dsl/309893 – sim Jul 19 '22 at 11:09
  • Yes I can see and they have given solution as well. I hope it will help you. – Sagar Patel Jul 20 '22 at 04:57

0 Answers0