【发布时间】:2015-11-12 13:21:15
【问题描述】:
我想为我的 Elasticsearch 文档结构生成一些文档。问题是我将嵌套的 JSON 存储在我的索引中,但我想记录 Elasticsearch 生成的扁平化 JSON 格式¹。
有没有一种类似于 Elasticsearch 使用 ES Java API 生成的方式来扁平化这个 JSON 的方法?
如果可能的话,我不想为这个任务启动 Elasticsearch。
示例 JSON:
{
"title": "Nest eggs",
"body": "Making your money work...",
"tags": [ "cash", "shares" ],
"comments": [
{
"name": "John Smith",
"comment": "Great article",
"age": 28,
"stars": 4,
"date": "2014-09-01"
},
{
"name": "Alice White",
"comment": "More like this please",
"age": 31,
"stars": 5,
"date": "2014-10-22"
}
]
}
在 Elasticsearch 将其展平后,文档将如下所示。
{
"title": [ eggs, nest ],
"body": [ making, money, work, your ],
"tags": [ cash, shares ],
"comments.name": [ alice, john, smith, white ],
"comments.comment": [ article, great, like, more, please, this ],
"comments.age": [ 28, 31 ],
"comments.stars": [ 4, 5 ],
"comments.date": [ 2014-09-01, 2014-10-22 ]
}
[1]https://www.elastic.co/guide/en/elasticsearch/guide/current/nested-objects.html
【问题讨论】:
-
something like this 或 this 有帮助吗?其他解决方案也是available here。
标签: java json elasticsearch flatten