1

I wrote the following code to set a template for new indexes:

from elasticsearch import Elasticsearch

doc = {
   "template": "te*",
  "settings": {
     "number_of_shards": 1
  },
  "mappings": {
     "type1": {
      "_source": {
         "enabled": "false"
       },
      "properties": {
        "host_name": {
          "type": "string",
          "index": "not_analyzed"
        },
        "created_at": {
          "type": "date",
          "format": "EEE MMM dd HH:mm:ss Z YYYY"
        }
      }
    }
  }
 }

 es = Elasticsearch([{'host': "127.0.0.1", "port": 9200}])
 es.put_template("f_1", body=doc)

The following error looks like some syntax error i can't solve:

launch(file, globals, locals) # execute the script
File "/Users/D/workspace/es_index_template/create_schema.py", line 31, in es.put_template("freshmilk_1", body=doc) File "/Users/D/.virtualenvs/es_index_template/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 69, in _wrapped return func(*args, params=params, **kwargs) File "/Users/D/.virtualenvs/es_index_template/lib/python2.7/site-packages/elasticsearch/client/init.py", line 1152, in put_template 'template', id), params=params, body=body) File "/Users/D/.virtualenvs/es_index_template/lib/python2.7/site-packages/elasticsearch/transport.py", line 329, in perform_request status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout) File "/Users/D/.virtualenvs/es_index_template/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.py", line 109, in perform_request self._raise_error(response.status, raw_data) File "/Users/D/.virtualenvs/es_index_template/lib/python2.7/site-packages/elasticsearch/connection/base.py",

line 108, in _raise_error raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info) elasticsearch.exceptions.TransportError: TransportError(500, u'script_parse_exception', u'unexpected field [mappings]')

Has someone an idea why he fails with the mappings?

2
  • What version of ES are you using? Commented Jul 18, 2016 at 18:59
  • @Loïc: "2.1.1" Thanks! Commented Jul 18, 2016 at 19:04

1 Answer 1

1

I took the put_template method as a query template but its meant to be a index template: Library usage should look like this:

es = Elasticsearch([{'host': "127.0.0.1", "port": 9200}])
IndicesClient(es).put_template(name="f_1", body=request_body)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.