elasticsearch - 无法创建弹性搜索映射或使日期字段工作
问题描述
{
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true."
}
"status" : 400
我读过上面的内容是因为在 elasticsearch 7.7 中不推荐使用类型,这对数据类型有效吗?我的意思是我该怎么说我希望将数据视为日期?我当前的映射有这个元素:
"Time": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
我只是想用 type:"date" 再次创建它,但我注意到即使复制粘贴当前映射(有效)也会产生错误......我拥有的索引和映射由https://github.com自动生成/jayzeng/scrapy-elasticsearch 我的目标只是拥有一个日期字段,我的所有日期都在我的索引中,但是当我想在 kibana 中过滤时,我可以看到它不被视为日期字段。而且修改映射似乎不是一种选择。这里有明显的 ELK 菜鸟,请与我裸露(:
解决方案
您遇到这种情况是因为7.0中有关命名文档类型的重大变化。
长话短说,而不是
PUT example_index
{
"mappings": {
"_doc_type": {
"properties": {
"Time": {
"type": "date",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}
}
}
你应该做
PUT example_index
{
"mappings": { <-- Note no top-level doc type definition
"properties": {
"Time": {
"type": "date",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}
}
我不熟悉你的 scrapy 包,但乍一看它似乎只是原生 py ES 客户端的包装器,它应该将你的映射定义转发给 ES。
警告:如果您将字段定义为text
并且打算将其更改为date
(或添加field
type date
),您将收到以下错误:
mapper [Time] of different type, current_type [text], merged_type [date]
你基本上有两个选择:
- 删除索引,设置新的映射并重新索引所有内容(最简单但会引入停机时间)
- 用一个新字段扩展映射,让我们调用它
Time_as_datetime
并使用 a 更新您现有的文档script
(引入一个全新的字段/属性——这有点冗长)
推荐阅读
- android - 慢速 Kotlin 自动完成 Android Studio
- php - Laravel 日历调度器
- python - YamlValidationException:运行 rasa train 时无法验证“domain.yml”
- javascript - 如何运行 jQuery 预览上传按钮?
- amazon-ec2 - 安装了 OSSEC 的 aws 自动缩放 AMI
- javascript - 如何将重定向链接添加到 onclick Material ui 图标 - React
- javascript - 在输入字段上调度 Enter keydown 事件
- flutter - 状态改变时 Flutter OpenContainer 重建?
- c - 我从 CS50x 中提出了我自己版本的“现金”问题,我可以优化它吗?
- python - SyntaxError:with 语句套件中的语法无效