Error while running search templates on ES 5.2.0 Unknown key for a VALUE_STRING in [id]

Hello,

I am trying to run searches using searchtemplates following are the commands i am executing

curl -XPUT 'localhost:9200/test/' -d '{"settings":{"index":{"number_of_shards":1,"number_of_replicas":0}}}'

curl -XPOST 'localhost:9200/test/testtype/1' -d '{"text":"value1_foo"}'
curl -XPOST 'localhost:9200/test/testtype/2?refresh=true' -d '{"text":"value2_foo value3_foo"}'
curl -XPOST 'localhost:9200/test/_refresh'

curl -XPUT 'localhost:9200/_search/template/my_template2' -d '{
  "template": {
    "query": {
      "match": {
        "text" : "{{my_value}}"
      }
    }
  }
}'
curl -XPOST 'localhost:9200/_refresh'

curl -XGET 'localhost:9200/test/_search/template' -d '{
  "template": {
    "id": "my_template2"
  },
  "params": {
    "my_value": "value1_foo"
  }
}'

{"error":{"root_cause":[{"type":"parsing_exception","reason":"Unknown key for a VALUE_STRING in [id].","line":1,"col":7}],"type":"parsing_exception","reason":"Unknown key for a VALUE_STRING in [id].","line":1,"col":7},"status":400}

Any helps appreciated.

Hi @Vikas_Mestry,

the syntax of the last statement is wrong. It should be:

curl -XGET "http://localhost:9200/test/_search/template" -d'
{
   "id": "my_template",
   "params": {
      "my_value": "value1_foo"
   }
}'

Daniel

1 Like

thanks @danielmitterdorfer that worked, my bad i should have read this in depth
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html#pre-registered-templates

Hi @Vikas_Mestry,

no worries. That happens to all of us. :slight_smile:

Daniel

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