Trouble with suggestions

i have a skills index with the following mapping:

{
  "skills" : {
    "mappings" : {
      "properties" : {
        "skill" : {
          "type" : "completion",
          "analyzer" : "simple",
          "preserve_separators" : true,
          "preserve_position_increments" : true,
          "max_input_length" : 50
        }
      }
    }
  }
}

The index is populated with around 2000 items. Here is a sample search result:

{"took":1,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":10000,"relation":"gte"},"max_score":1.0,"hits":[{"_index":"skills","_id":"ZjQtMIUB7n2f4Nbeg4Qr","_score":1.0,"_source":
    {
      "skill": "liderazgo de equipos"
    }
    },{"_index":"skills","_id":"ZzQtMIUB7n2f4Nbeg4Q-","_score":1.0,"_source":
    {
      "skill": "key account management"
    }
    },{"_index":"skills","_id":"aDQtMIUB7n2f4Nbeg4RN","_score":1.0,"_source":
    {
      "skill": "security"
    }
    },{"_index":"skills","_id":"aTQtMIUB7n2f4Nbeg4Ra","_score":1.0,"_source":
    {
      "skill": "quality assurance"
    }
    },{"_index":"skills","_id":"ajQtMIUB7n2f4Nbeg4Ro","_score":1.0,"_source":
    {
      "skill": "healthcare management"
    }
    },{"_index":"skills","_id":"azQtMIUB7n2f4Nbeg4R1","_score":1.0,"_source":
    {
      "skill": "program development"
    }
    },{"_index":"skills","_id":"bDQtMIUB7n2f4Nbeg4SG","_score":1.0,"_source":
    {
      "skill": "curriculum development"
    }
    },{"_index":"skills","_id":"bTQtMIUB7n2f4Nbeg4SU","_score":1.0,"_source":
    {
      "skill": "hospitality"
    }
    },{"_index":"skills","_id":"bjQtMIUB7n2f4Nbeg4Sh","_score":1.0,"_source":
    {
      "skill": "supply chain"
    }
    },{"_index":"skills","_id":"bzQtMIUB7n2f4Nbeg4Sv","_score":1.0,"_source":
    {
      "skill": "investments"
    }
    }]}}

when i run


curl -X POST "localhost:9200/skills/_suggest" -H 'Content-Type: application/json' -d'
{
  "skill-suggest": {
    "prefix": "ja",
    "completion": {
      "field": "skill"
    }
  }
}
'

i get an error:

{"error":"no handler found for uri [/skills/_suggest] and method [POST]"}

The index does exist(i am able to list its content).
The elasticsearch endpoint is the correct one - i am able to run other queries successfully.
Elasticsearch is running and accesible.

Running

curl -X POST "localhost:9200/skills/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "_source": "suggest",     
  "suggest": {
    "song-suggest": {
      "prefix": "ja",
      "completion": {
        "field": "skill", 
        "size": 5           
      }
    }
  }
}
'
{
  "took" : 11,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "suggest" : {
    "song-suggest" : [
      {
        "text" : "ja",
        "offset" : 0,
        "length" : 2,
        "options" : [
          {
            "text" : "japan",
            "_index" : "skills",
            "_id" : "kTQvMIUB7n2f4NbeXqFg",
            "_score" : 1.0,
            "_source" : { }
          },
          {
            "text" : "japan",
            "_index" : "skills",
            "_id" : "oTQxMIUB7n2f4NbevcgW",
            "_score" : 1.0,
            "_source" : { }
          },
          {
            "text" : "japan",
            "_index" : "skills",
            "_id" : "sTQ0MIUB7n2f4NbeIu8F",
            "_score" : 1.0,
            "_source" : { }
          },
          {
            "text" : "japan",
            "_index" : "skills",
            "_id" : "wTU2MIUB7n2f4NbefBZJ",
            "_score" : 1.0,
            "_source" : { }
          },
          {
            "text" : "japan",
            "_index" : "skills",
            "_id" : "0TU5MIUB7n2f4NbeHj2R",
            "_score" : 1.0,
            "_source" : { }
          }
        ]
      }
    ]
  }
}

gives 5 disappointing "japan" results, even though i have 100% unique values in the skills index.

Expectation: find a way to get relevant suggestions. Typing "ja" should give me answers such as java, javascript.

Hi @Mihai_Raulea

Please use the code formatting tools in the code snippets. Using vc formatting helps everyone understand and reproduce your problem.

autocomplete - elasticsearch completion suggester returns only one suggestion when more than one matches - Stack Overflow -- it's basically the same problem.

Hi Rabbit, i have formatted my query. Thanks!

I understand that you want to manipulate the order of suggestions. In that case I think using weight can help

weight: A positive integer or a string containing a positive integer, which defines a weight and allows you to rank your suggestions. This field is optional.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.