首页 > 解决方案 > 如何在 elasticsearch python 低级客户端中指定 index.mapping.ignore_malformed?

问题描述

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','不同类型的映射器[table.rows.endDate],current_type [date],merged_type [text]')

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

标签: pythonelasticsearch

解决方案


您可以使用以下参数创建索引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"
        }
      }
    }
  }
}

推荐阅读