python - 如何在elasticsearch python低级客户端中指定index.mapping.ignore_malformed?

标签 python elasticsearch

from elasticsearch import Elasticsearch
es = Elasticsearch()
es.indices.create(index='report', ignore=400)
es_reponse = es.index(index='reports',doc_type='text',body=report_json)

我正进入(状态

RequestError(400, 'illegal_argument_exception', 'mapper [table.rows.endDate] of different type, current_type [date], merged_type [text]')



此错误,可以通过将index.mapping.ignore_malformed设置为false来解决:但是,我不知道在代码中的哪里指定?
我正在使用elasticsearch 7.0.5

最佳答案

您可以在Python中使用以下参数创建索引:

from elasticsearch_dsl import Index
from elasticsearch import Elasticsearch

es=Elasticsearch(['ES_URL:ES_PORT'])


index = Index('my_index', es)
index.settings(
     number_of_shards=6,
     number_of_replicas=2,
     index={'mapping':{'ignore_malformed':False}}) //or True
index.create()

这就是Elasticsearch上的样子:
[root@host]$ curl -XGET ES_URL:ES_PORT/my_index/_settings?pretty
{
  "my_index" : {
    "settings" : {
      "index" : {
        "mapping" : {
          "ignore_malformed" : "false"
        },
        "number_of_shards" : "6",
        "provided_name" : "my_index",
        "creation_date" : "1573646292390",
        "number_of_replicas" : "2",
        "uuid" : "e__BuX-KSSeoR2LXQXaWkA",
        "version" : {
          "created" : "6020499"
        }
      }
    }
  }
}

关于python - 如何在elasticsearch python低级客户端中指定index.mapping.ignore_malformed?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58835485/

相关文章:

java - 将 Oracle/关系表中的数据索引到 Elasticsearch 中的更好方法是什么?

elasticsearch - Elasticsearch脚本查询无痛指数函数

python - RuntimeWarning : DateTimeField Model. 当时区支持处于事件状态时,日期收到了幼稚的日期时间

python - 我如何告诉 boto 操作成功?

python - Python 项目的预提交 Hook

elasticsearch - Elasticsearch Ordering术语聚合在 HitTest 门命中子聚合之后的存储桶

java - java中的 Elasticsearch 查询

filter - Elasticsearch 过滤查询,查询部分被忽略?

python - 如何通过回调更新 PyQt 中的散点图?

python - Flask-sqlalchemy - 计算请求 REST 端点(或数据库记录)的次数