json - Elasticsearch 将嵌套的 json 视为纯字符串:无法在 start_object 上获取文本
问题描述
我正在尝试添加一些弹性的 json 文档,它们具有深层嵌套的 json 结构。
我想将其中一些嵌套字段视为普通的未索引text
而不是 json 或skip,或者它们是不可能的。
例如,我有这样的event
文件:
{
"cluster": "production1",
"header": {
"os": "ios",
"experiments": {
"e1": {
"field1": "value1",
"field2": "value2"
"array": ["id0"]
},
"e2": {
"field3" : "value3",
"array": ["id1", "id2", "id3"]
}
}
},
}
我希望header.experiments
字段下的所有内容都被视为一个纯文本。
我试过这个映射,但它对我不起作用,因为experiments
field 是 object 而不是 string: error: can't get text on a start_object
。
"mappings": {
"event": {
"properties": {
"cluster": {
"type": "keyword",
"index": true
},
"header": {
"os": {
"type": "keyword",
"index": true
},
"experiments": {
"type": "text", // This does not work
"index": false
}
}
}
}
}
如何让 ElasticSearch 将子字段视为纯文本?
解决方案
要完全跳过该字段,您可以在该字段的索引映射中设置enabled
为:false
experiments
"mappings": {
"event": {
"properties": {
"cluster": {
"type": "keyword",
"index": true
},
"header": {
"os": {
"type": "keyword",
"index": true
},
"experiments": {
"enabled": false
}
}
}
}
}
该
enabled
设置只能应用于映射类型和object
字段,导致 Elasticsearch 完全跳过对字段内容的解析。JSON 仍然可以从该_source
字段中检索,但不可搜索或以任何其他方式存储:
有关详细信息,请参阅:
https ://www.elastic.co/guide/en/elasticsearch/reference/current/enabled.html
推荐阅读
- authentication - 如何在没有企业的情况下保护 DC/OS 上的 HDFS
- php - jquery如何在不刷新页面的情况下发布到数组
- java - 如何从Android中的JSON数组中获取任何字符串
- php - 检查记录是否存在并返回一个布尔值并将其与表单中的输入进行比较
- mysql - SQL 选择过去 45 天的所有数据
- neo4j - 查询返回子图和所有内部关系
- javascript - 如何在网络上使用 mathJax 或类似工具格式化字谜中的字符
- python - 如何在 tensorflow 会话中运行 Keras.model() 进行预测?
- c - 如何解决警告问题?
- react-native - React Native - 将 Ace-Editor 与 React Native 应用程序集成