使用elasticsearch构建帖子/评论系统的最佳方法是什么?我正在使用elasticsearch作为辅助数据库。
会有一个带有多线程评论系统的帖子,可能有两个层次。每个帖子最多可以有500-1000条评论。将有两个喜欢和评论为每个评论和帖子增量计数器。这意味着大量的索引。另外,我想获取他们对应用过滤器的评论的博客文章。
现在,我的结构是这样的。在这种情况下,博客文章和用户详细信息很少被编辑,但是标签和评论会被频繁添加。
{
"_index": "brainstormer_ideas_with_comments",
"_type": "_doc",
"_id": "1",
"_version": 1,
"_seq_no": 0,
"_primary_term": 1,
"found": true,
"_source": {
"id": 1,
"brainstormer_id": 1,
"idea": "cCZhvy",
"description": "2jJPo3hYbqeh2VBnDJeGtylVu7qfe_MRp77hTK6t7SN57GzeQG8c",
"user": {
"id": "user-1",
"login": "pO2DSqIS--"
},
"created_at": "2020-08-13T20:35:17+00:00",
"like_count": 41,
"comment_count": 45,
"tags": [
"bU37X",
"a_Rl5b",
"vxD.ZMo",
"AmvtHVuQ",
"yx9oSx-_D"
],
"comments": [
{
"id": "comment-1",
"comment": "7ewh-Cqf4gQqmIK53jXbR7",
"tags": [
"mJN",
"jFm-",
"hV0pi",
"ONGNOw",
"HtzmDfO",
"dawVLk09"
],
"created_at": "2020-08-08T20:35:17+00:00",
"user": {
"id": "user-1",
"login": "Tl6CDNawUh"
}
},
{
"id": "comment-1",
"comment": "BKj8sAcbJJXWxAPk3HQFTZWtvQm",
"tags": [
"sYj",
"XRLw",
"xtAeH",
"Oq6dBR",
"lj4_hOI",
"n3lhc2ig"
],
"created_at": "2020-09-21T20:35:17+00:00",
"user": {
"id": "user-2",
"login": "AF3KT415uf"
}
},
{
"id": "comment-1",
"comment": "vzt7XEe2WIP3OszpLmcF8J",
"tags": [
"YCH",
"kodm",
"RGv2B",
"Qk5R1D",
"ICrDjmz",
"4mmfLK16"
],
"created_at": "2020-07-08T20:35:17+00:00",
"user": {
"id": "user-3",
"login": "7xTLOuCeWD"
}
},
{
"id": "comment-1",
"comment": "Jm6E3PrlOI",
"tags": [
"IrZ",
"TJlf",
"__HQy",
"5VH2Vs",
"btvxG51",
"5iRoVR_k"
],
"created_at": "2020-07-19T20:35:17+00:00",
"user": {
"id": "user-4",
"login": "zr32RlxNak"
}
},
{
"id": "comment-1",
"comment": "jKGzoZhCpUv4DrvoebamXLnmvyX_CK0",
"tags": [
"Osa",
"OKlQ",
"cBcjt",
"2BcQD7",
"K7lLhS7",
"ZK1t_GXl"
],
"created_at": "2020-07-14T20:35:17+00:00",
"user": {
"id": "user-5",
"login": "B8LGMpPWwv"
}
},
{
"id": "comment-1",
"comment": "L-PryTXsa1FbEnIJdH_5vlsdpfnckB1kmMJI4EVwszhc45qlW6e",
"tags": [
"kRJ",
"Mkka",
"ari.I",
"pgWcUk",
"w78vFir",
"eOx.zRx9"
],
"created_at": "2020-08-07T20:35:17+00:00",
"user": {
"id": "user-6",
"login": "IG1Oo_fOcr"
}
}
]
}
}
使用嵌套对象、父/子对象或其他对象更好吗?任何关于ElasticSearch的结构和更新频率的建议都将不胜感激。
谢谢,
1条答案
按热度按时间q9rjltbz1#
嵌套对象和父子关系都很昂贵,有关详细信息,请阅读“嵌套对象的麻烦”博客文章。
一种方法是在elasticsearch中为主帖子上的每条评论/回复创建一个单独的文档,而不是严格的父子关系,只需要有一个字段来告诉什么是父帖子,即文档之间存在松散耦合/关系。
elasticsearch的默认刷新间隔为1秒,用于提供nrt,如果需要,可以保留此默认值或根据您的用例和性能要求对其进行微调。