如何存储有关用户已阅读哪些通知的信息? [英] How to store info regarding which notifications have been read by user?
问题描述
我在弹性搜索中存储了一组通知或信息项.用户看到通知后,我需要将其标记为该用户看到的.用户可以按已读/未读状态过滤文档.通知将被许多用户查看,看到的状态将不断更新.什么是存储此数据的最佳方法.我应该将已经看到该通知的用户列表存储在同一文档中,还是应该创建父子关系.
I have a set of notification or information items stored in elasticsearch. Once a user has seen a notification I need to mark it as seen by that user. A user can filter documents by read/unread status. Notifications will be viewed by lot of users and seen status will constantly get updated. What is the best way to store this data. Shall I store the list of users which have seen that notification in same document itself or shall I create parent child relationship.
推荐答案
请确保避免使用父子类型或嵌套类型,因为它们的计算量很大.实现与大量数据的关系的最佳方法是对数据进行非规范化并将其置于不同的索引中.请在此处和
For sure you should avoid parent-child or nested type because they are computationial costful. the best way to achieve the relationship with a lot of data is to denormalize your data and put them in different indices. Please read here and here .Example:
PUT notification
{"mappings": {
"properties": {
"content": {
"type": "text"},
"id_notification":{
"type":"keyword" }{
}}
}
}
然后,用户索引:
PUT user
{"mappings": {
"properties": {
"general_information": {
"type": "text"},
"id_user":{
"type":"keyword" }{
}}
}
}
关系的另一个索引:
PUT seen
{"mappings": {
"properties": {
"seen": {
"notification_id":{
"type": "keyword",
"fields":{
"user_id":{
"type":"keyword"}}},
"unseen":{
"notification_id":{
"type": "keyword",
"fields":{
"user_id":{
"type":"keyword"}}}}
}
}
对不起,文本格式,我现在还没有基巴纳语.您应该注意,从信息索引(用户,通知)到支持索引(已看到),您应该进行多索引查询-doc
Sorry for the text format, i haven't kibana now. You should pay attention that to pass from information indices - user, notification - to the support index - seen - you should make a multi-index query - doc here. it will works because the name and the values of the fields - user_id , notification_id - are the same in different indices. The subfields user_id in seen index are array of keywords. However you could make user_id a single keyword and parent of notification_id keyword array field. In every case they keep the one to many realtionship, the best choice depends from your data
这篇关于如何存储有关用户已阅读哪些通知的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!