我想要将一个嵌套的JSON对象展平,例如{"a":{"b":1}}
变成{"a.b":1}
,以便在solr中处理它。
我有11 TB的JSON文件,其中包含嵌套和带有字段名称中点的情况,这意味着elasticsearch(用点表示)或solr(嵌套但没有_childDocument_
符号)不能直接处理这些文件。
其他解决方案是将字段名称中的点替换为下划线,并将其推送到ElasticSearch,但是我对Solr的使用经验更好,因此我更喜欢展平解决方案(除非Solr可以直接处理这些嵌套的JSON??)。
如果处理速度比Solr快得多,我将优先选择Elasticsearch,因为我的优先级是尽可能快地处理(因此我选择了jq而不是在Python中编写脚本)。
请帮帮我。
编辑:
我认为第3个和第4个示例可以解决我的问题:https://lucidworks.com/blog/2014/08/12/indexing-custom-json-data/
我很快就会试试。
{"a":{"b":[1]}}
,会引发错误:jq: error (at <stdin>:1): string (".") and number (0) cannot be added。 - Steve Amerige[leaf_paths as $path | {"key": [$path[] | tostring] | join("."), "value": getpath($path)}] | from_entries
- Abhijit