0

My code is

curl -XGET 'http://localhost:9200/web/_suggest?pretty' -d '
{ "brand-suggest": {"completion": {"field": "nameSuggest","size":   "5","context": { "private": "false" }}, "text": "sampl"}}'

I have an error while trying in elasticsearch suggest query.

"index" : "webpage",
      "shard" : 4,
      "status" : 500,
      "reason" : "BroadcastShardOperationFailedException[[tellofy][4] ];  nested: ElasticsearchException[failed to execute suggest]; nested: ElasticsearchIllegalArgumentException[suggester [completion] doesn't expect any context]; "
    }

What is the reason for the above error. I can't able to find the cause of that error.

Avihoo Mamka
  • 4,656
  • 3
  • 31
  • 44
venkat
  • 73
  • 2
  • 14
  • Can you provide the mapping of the nameSuggest field? – Val Aug 18 '16 at 09:37
  • zmy namesuggest is a jsonObject. mappingJSON.put("nameSuggest", new JSONObject( "{\"type\": \"completion\", \"analyzer\" : \"simple\", \"search_analyzer\" : \"simple\" , \"context\" : \"simple\"}")); – venkat Aug 18 '16 at 10:01

1 Answers1

1

nameSuggest has a completion type but without context, so your suggest query is not allowed to specify a context

See the difference between normal completion fields and completion fields with context

If you wish to run the following query

curl -XGET 'http://localhost:9200/web/_suggest?pretty' -d '{
  "brand-suggest": {
    "completion": {
      "field": "nameSuggest",
      "size": "5",
      "context": {
        "private": "false"
      }
    },
    "text": "sampl"
  }
}'

You need to change the mapping of your nameSuggest field to this i.e. add a context configuration section:

{
  "type": "completion",
  "analyzer": "simple",
  "search_analyzer": "simple",
  "context": {
    "private": {
      "type": "category",
      "path": "private"
    }
  }
}
Val
  • 207,596
  • 13
  • 358
  • 360
  • Hi Mr Val . thanks for your suggestion. , Initially i need to check whether it is correct . for that i run above curl command in my terminal. here you asked me to change my context , for terminal what i need to change in above curl... "context" . – venkat Aug 18 '16 at 11:05
  • You simply need to remove the `context` section from your query and it will work – Val Aug 18 '16 at 11:06
  • But i need to check condition that what are all private ("false") along with my text ("samp1") . – venkat Aug 18 '16 at 11:11
  • Then you need the context :) There's no other way. – Val Aug 18 '16 at 11:12
  • My actual question is in below link. "http://stackoverflow.com/questions/38995684/elasticsearch-suggest-condition-check/38999497#38999497" Can you help, based on above link question. – venkat Aug 18 '16 at 11:15
  • I understand, but you need to modify your mapping as I suggested in order for this to work. – Val Aug 18 '16 at 11:16
  • yes i got a solution . That is due to mapping issue ,After deleted my previous elasticsearch indexes and saved newly it works fine. – venkat Aug 19 '16 at 11:00