如何在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','mapper不同类型的[table.rows.endDate],current_type [date],merged_type [text]')
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
this error and can be solved by setting index.mapping.ignore_malformed : false, But I don't know where to specify this in code?
i am using elasticsearch 7.0.5
答
您可以在 Python
中使用以下参数创建带有此参数的索引:
You can create index with this parameter in Python
with:
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"
}
}
}
}
}