elasticsearch - ElasticSearch 覆盖从文本到对象的映射
问题描述
我正在尝试覆盖字段的映射。
有一个默认索引模板(我无法更改),我用自定义模板覆盖它。
默认索引将“消息”字段映射为文本,但我需要将其视为对象并使其字段可索引/可搜索。
这是默认的索引模板,顺序为 10。
{
"mappings": {
"_default_": {
"dynamic_templates": [
{
"message_field": {
"mapping": {
"index": true,
"norms": false,
"type": "text"
},
"match": "message",
"match_mapping_type": "string"
}
},
...
],
"properties": {
"message": {
"doc_values": false,
"index": true,
"norms": false,
"type": "text"
},
...
}
}
},
"order": 10,
"template": "project.*"
}
这是我的覆盖:
{
"template" : "project.*",
"order" : 100,
"dynamic_templates": [
{
"message_field": {
"mapping": {
"type": "object"
},
"match": "message"
}
}
],
"mappings": {
"message": {
"enabled": true,
"properties": {
"tag": {"type": "string", "index": "not_analyzed"},
"requestId": {"type": "integer"},
...
}
}
}
}
这很好用,但我最终在“消息”对象中定义了所有字段(标签、requestId、...)。
有没有办法让“消息”对象中的所有字段都可索引/可搜索?
这是一个示例文档:
{
"level": "30",
...
"kubernetes": {
"container_name": "data-sync-server",
"namespace_name": "alitest03",
...
},
"message": {
"tag": "AUDIT",
"requestId": 1234,
...
},
}
...
}
尝试了很多东西,但我无法让它工作。
我正在使用 ElasticSearch 2.4.4 版。
解决方案
您可以在动态映射中使用path_match属性:
就像是 :
{
"template": "project.*",
"order": 100,
"mappings": {
"<your document type here>": {
"dynamic_templates": [
{
"message_field": {
"mapping": {
"type": "object"
},
"match": "message"
}
},
{
"message_properties": {
"path_match": "message.*",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}
]
}
}
}
但是您可能必须区分字符串/数字match_mapping_type
推荐阅读
- node.js - 如何设置查询以在猫鼬中选择数组元素
- javascript - 为 jQuery post 构造 post 数据
- python - 将 for 循环的每次迭代的输出保存在单个文件中
- reactjs - 打字稿将样式化的组件道具与父组件合并
- python - Python Pandas 转换日期
- discord.js - 为什么我的代码在不应该运行的时候运行?
- arrays - 替换 bash 中的文件/数组内容
- python - 为什么新创建的 virtualenv 包含 python ros 包?
- c# - .NET C# - 无法加载文件或程序集 [...] 或其依赖项之一。该系统找不到指定的文件
- react-native - 在 React Native 的 UI 管理器中找不到 RNSVGTSpan