简体   繁体   English

ACID更新ElasticSearch文档

[英]ACID update of ElasticSearch Document

I'm trying to build a Tinder-like system right now. 我现在正在尝试构建类似Tinder的系统。 Here I need to know which cards have already been seen. 在这里,我需要知道已经看过哪些卡。

If I save the cards in ElasticSearch, and then have such a document: 如果我将卡片保存在ElasticSearch中,然后有这样一个文档:

{ nama: David, location: {lat, lon}, seenFromUsers: [] } {nama:David,位置:{lat,lon},seenFromUsers:[]}

I'm just wondering if it makes sense to create a list in the object itself. 我只是想知道在对象本身中创建列表是否有意义。 Probably there are 2000 entries in it. 大概有2000个条目。 But if I do an update in ElasticSearch, then I always have to pass all 2000 entries. 但是,如果我在ElasticSearch中进行更新,那么我总是必须传递所有2000个条目。 If two users do this at the same time, does one get lost? 如果两个用户同时执行此操作,一个人会迷路吗? How can I simply add another ID to the array? 如何简单地将另一个ID添加到阵列? Is that even possible? 那有可能吗?

What other solutions are there? 还有什么其他解决方案?

One other solution would be a complete different approach. 另一种解决方案是完全不同的方法。 Instead if creating documents like this 相反,如果创建这样的文档

{
  "name": "David",
  "location": { "lat": ..., "lon": ...},
  "seenFromUsers": ["Laura", "Simone"]
}

think in Relations like this: 在关系中这样想:

{
  "name": "David",
  "seenBy": "Laura"
}

{
  "name": "David",
  "seenBy": "Simone"
}

this approach will give you simpler queries, and the ACID problem is solved. 这种方法将为您提供更简单的查询,并且解决了ACID问题。 New profile views are simply new documents... 新的个人资料视图只是新的文档...

As a benefit, you´ll get rid of inner objects and it will be more easy to add additional data to this relation: 作为一项好处,您将摆脱内部对象,并且向此关系添加其他数据将更加容易:

{
  "name": "David",
  "seenBy": "Laura",
  "timestamp": ...,
  "liked": true
}

{
  "name": "David",
  "seenBy": "Simone",
  "timestamp": ...,
  "liked": false
}

And now you´ll be able to do a simple query for all positive likes of a profile, or bi-directional likes/matches... 现在,您可以对个人资料的所有正面喜欢或双向喜欢/匹配进行简单的查询...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM