elasticsearch 如何更新Elasticsearch中的映射以更改字段数据类型和字符串中分析器的类型
尝试更新映射时,出现以下错误:elasticsearch 如何更新Elasticsearch中的映射以更改字段数据类型和字符串中分析器的类型,elasticsearch,mapping,elasticsearch,Mapping,尝试更新映射时,出现以下错误: {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"mapper [timestamp] of different type, current_type [string], merged_type [date]"}],"type":"illegal_argument_exception","reason":" mapper [timestamp] of different t
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"mapper [timestamp] of different type, current_type [string], merged_type [date]"}],"type":"illegal_argument_exception","reason":"
mapper [timestamp] of different type, current_type [string], merged_type [date]"},"status":400}
{"root_cause":[{"type":"illegal_argument_exception","reason":"Mapper for [AppName] conflicts with existing mapping in other types:\n[mapper [AppName] has different [index] values, mapper [App
different [doc_values] values, cannot change from disabled to enabled, mapper [AppName] has different [analyzer]]"}],"type":"illegal_argument_exception","reason":"Mapper for [AppName] conflict with
existing mapping in other types:\n[mapper [AppName] has different [index] values, mapper [AppName] has different [doc_values] values, cannot change from disabled to enabled, mapper [AppName]
rent [analyzer]]"},"status":400}
我正在尝试在windows上运行以下命令
curl -XPUT localhost:9200/logstash-*/_mapping/log?update_all_types -d "{
"properties":
{
"timestamp":
{
"type": "date",
"format": "MM-dd-yyyy HH:mm:ss",
"fielddata":{"loading" : "lazy"} }
}
}";
如何将日期字段的数据类型从字符串更改为具有特定格式的日期类型
我试图更改字符串数据类型的映射,将其更改为eager
加载和not\u analysisd
from analysisd,但它给出了以下错误:
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"mapper [timestamp] of different type, current_type [string], merged_type [date]"}],"type":"illegal_argument_exception","reason":"
mapper [timestamp] of different type, current_type [string], merged_type [date]"},"status":400}
{"root_cause":[{"type":"illegal_argument_exception","reason":"Mapper for [AppName] conflicts with existing mapping in other types:\n[mapper [AppName] has different [index] values, mapper [App
different [doc_values] values, cannot change from disabled to enabled, mapper [AppName] has different [analyzer]]"}],"type":"illegal_argument_exception","reason":"Mapper for [AppName] conflict with
existing mapping in other types:\n[mapper [AppName] has different [index] values, mapper [AppName] has different [doc_values] values, cannot change from disabled to enabled, mapper [AppName]
rent [analyzer]]"},"status":400}
以下是我对相同问题的查询:
curl -XPUT localhost:9200/logstash-*/_mapping/log?update_all_types -d "{
"properties":
{"AppName":
{
"type": "string",
"index" : "not_analyzed",
"fielddata":{"loading" : "eager"}
}
}
}"
但是,如果我将其从
not_analysisd
更改为analysisd
,它将给出一条acknowledged=true
消息。如何更改分析器 无法更改现有的数据类型映射。正如弹性文件所说:
虽然可以添加到现有映射,但不能更改现有字段映射。如果某个字段已存在映射,则该字段中的数据可能已被索引。如果要更改字段映射,索引数据将是错误的,并且无法正确搜索
我们可以更新映射以添加新字段,但不能更改
已分析到未分析的现有字段
您唯一的选择是使用新映射创建新索引,并将数据从旧索引重新索引到新索引。否,您不能更改单个字段定义 如果要在单个类型中更改单个字段的字段定义,除了对索引中的所有文档重新编制索引外,您别无选择
为什么不能更改映射?本文解释 为了使 你的数据可以搜索,你的数据库需要知道什么类型的数据 每个字段都包含索引,以及应如何对其进行索引 如果你换一个 字段类型,例如从字符串到日期,该字段的所有数据 已编制索引的字段将变得无用。单程还是单程 另外,您需要重新索引该字段 这不仅适用于Elasticsearch,也适用于任何使用 用于搜索的索引。如果它没有使用索引,那么它就是 以牺牲速度换取灵活性
索引字段类型不正确的文档时会发生什么情况? 将尝试转换。如果不存在有效转换,将引发异常 有关于示例的注释,输入了
字符串
,但预期为长
。将尝试转换。但如果不存在有效转换,则仍将引发异常
[…]如果该字段已存在
映射为long类型,然后ES将尝试转换字符串
如果不能,则抛出异常
我是否可以对文档进行索引,忽略格式错误的字段? 对。ES5提供了一个
ignore\u格式错误的映射
参数。解释说,
尝试将错误的数据类型索引到字段中会引发以下异常:
默认值,并拒绝整个文档。ignore\u格式不正确
参数,如果设置为true,则允许忽略异常最新版本
格式错误的字段未编入索引,但文档中的其他字段已编入索引
正常处理。