elasticsearch - 如何在 Elasticsearch 中声明嵌套字段的映射以允许存储不同的类型?
问题描述
本质上,我希望我的映射尽可能无模式,但允许嵌套类型并能够存储可能具有不同类型的数据:
当我尝试添加某些字段具有不同类型值的文档时,我收到如下错误:
“type”:“illegal_argument_exception”,“reason”:“不同类型的映射器 [data.customData.value],current_type [long],merged_type [text]”
这可以通过将字段值映射到文本来轻松解决(或通过首先插入仅包含文本的文档来动态创建它)。但是,我想避免使用模式。也许将所有嵌套在 customData 中的字段设置为文本?我怎么做?
我早些时候遇到了这个问题,但是在意外地设法获得一个有效的动态映射后它开始工作(因为一切都被视为文本。我后来意识到这个问题,因为我需要更改映射以允许嵌套类型。
这种数据的文档很难存储成功:
"customData": [
{
"value": "some_text",
"key": "some_text"
},
{
"value": 0,
"key": "some_text"
}
]
映射的一部分有效:
{
"my_index": {
"aliases": {},
"mappings": {
"_doc": {
"properties": {
"data": {
"properties": {
"customData": {
"properties": {
"key": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"value": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
},
"some_list": {
"type": "nested",
"properties": {
"some_field": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
}
}
本质上,我希望映射尽可能无模式,但允许嵌套类型并能够存储可能具有不同类型的数据:
{
"mappings": {
"_doc": {
"properties": {
"data": {
"type": "object"
},
"somee_list": {
"type": "nested"
}
}
}
}
}
那么解决这个问题的最佳方法是什么?
解决方案
推荐阅读
- javascript - React App 在使用上下文 API 时出错
- flutter - 未处理的异常:NoSuchMethodError:在 null 上调用了 getter 'length'。不知道原因
- javascript - React Native:在应用中显示您的 App Store 评分?(iOS/安卓)
- c# - 从数据库中检索字符串并与日期进行比较
- php - php artisan 命令在 laravel 中不起作用
- kotlin-coroutines - CancelableContinuation 的 invokeOnCancellation 处理程序中的异常
- reactjs - 尽管有数据,但地图功能未在列表项中呈现数据
- javascript - jsx return 语句中的条件
- javascript - 将复选框值收集为数组 React
- reactjs - React JS - 为什么要单击两次按钮?