我正在嘗試使用動態映射創建索引。映射模板中似乎有一些錯誤。資料集包含字串、數值和日期。我必須容納所有這些。
mapping = {
"settings": {
"number_of_shards": 2,
"number_of_replicas": 1
},
"mappings": {
"_doc": {
"properties": {
"details": {
"dynamic_templates": [
{
"name_template": {
"match": "*",
"mapping": {
"type": "string",
"dynamic": True
}
}
}
]
}
}
這是我用來創建新索引的代碼
if es.indices.exists(index="es_index") == False:
index_creation = es.indices.create(index="es_index", ignore=400, body=mapping)
print("index created: ",index_creation)
我收到錯誤
index created: {'error': {'root_cause':
[{'type': 'mapper_parsing_exception', 'reason': 'Root mapping definition has
unsupported parameters: [details : {dynamic_templates=[{name_template=
{mapping={dynamic=true, type=string}, match=*}}]}]'}], 'type': 'mapper_parsing_exception', 'reason': 'Failed to parse mapping [_doc]:
Root mapping definition has unsupported parameters: [details : {dynamic_templates=[{name_template={mapping={dynamic=true, type=string}, match=*}}]}]', 'caused_by': {'type': 'mapper_parsing_exception', 'reason': 'Root mapping definition has unsupported parameters: [details : {dynamic_templates=[{name_template={mapping={dynamic=true, type=string}, match=*}}]}]'}}, 'status': 400}
uj5u.com熱心網友回復:
你沒有正確地做動態模板,它應該是這樣的。dynamic_templates應該在它自己的陣列中作為屬性的兄弟。你也不需要指定_doc:
mapping = {
"settings": {
"number_of_shards": 2,
"number_of_replicas": 1
},
"mappings": {
"dynamic_templates": [
{
"name_template": {
"path_match": "details.*",
"mapping": {
"type": "text"
}
}
}
],
"properties": {
"details": {
"type": "object"
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/428929.html
