【问题标题】:Script Parse Exception with python elasticsearch API使用 python elasticsearch API 的脚本解析异常
【发布时间】:2016-11-21 11:50:53
【问题描述】:

我编写了以下代码来设置新索引的模板:

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)

以下错误看起来像是一些我无法解决的语法错误:

launch(file, globals, locals) # 执行脚本
文件“/Users/D/workspace/es_index_template/create_schema.py”,第 31 行, 在 es.put_template("freshmilk_1", body=doc) 文件 "/Users/D/.virtualenvs/es_index_template/lib/python2.7/site-packages/elasticsearch/client/utils.py", 第 69 行,在 _wrapped 中 返回 func(*args, params=params, **kwargs) 文件 "/Users/D/.virtualenvs/es_index_template/lib/python2.7/site-packages/elasticsearch/client/init.py ", 第 1152 行,在 put_template 中 'template', id), params=params, body=body) 文件 "/Users/D/.virtualenvs/es_index_template/lib/python2.7/site-packages/elasticsearch/transport.py", 第 329 行,在 perform_request 中 状态、标头、数据 = connection.perform_request(方法、url、参数、正文、忽略=忽略、超时=超时)文件 "/Users/D/.virtualenvs/es_index_template/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.py", 第 109 行,在 perform_request 中 self._raise_error(response.status, raw_data) 文件“/Users/D/.virtualenvs/es_index_template/lib/python2.7/site-packages/elasticsearch/connection/base.py”,

第 108 行,在 _raise_error 引发 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]')

有人知道为什么他的映射失败了吗?

【问题讨论】:

  • 你用的是什么版本的ES?
  • @Loïc:“2.1.1”谢谢!

标签: python elasticsearch


【解决方案1】:

我将 put_template 方法作为查询模板,但它的本意是索引模板: 库的使用应如下所示:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-04
    • 1970-01-01
    • 1970-01-01
    • 2020-12-03
    • 1970-01-01
    • 1970-01-01
    • 2019-01-28
    相关资源
    最近更新 更多