简体   繁体   English

如何构建和搜索 Elasticsearch

[英]How to structure and search Elasticsearch

I'm building a Rails app with two models Users & Documents.我正在构建一个带有两个模型用户和文档的 Rails 应用程序。 A user can have 1,000s of documents.一个用户可以拥有 1,000 个文档。

I'm looking for advice on how to set this up with Rails and Elasticsearch.我正在寻找有关如何使用 Rails 和 Elasticsearch 进行设置的建议。 Should I use an index per each user in Elasticsearch?我应该在 Elasticsearch 中为每个用户使用一个索引吗?

Also, right now when I perform Document.search, it is returning @documents results for all users.另外,现在当我执行 Document.search 时,它会为所有用户返回 @documents 结果。 What is the right way to limit search results to the particular Document.user_id.将搜索结果限制为特定 Document.user_id 的正确方法是什么。 I'm guessing these two questions are related which is why I included them in one question.我猜这两个问题是相关的,这就是我将它们包含在一个问题中的原因。

Unless you were going to have a very small number of users with a very large (100s of thousands and more) you almost definitely don't want an index per user.除非您的用户数量非常少,但用户数量非常大(成百上千甚至更多),否则您几乎肯定不希望每个用户都有一个索引。 There is a per index overhead which would become significant with large numbers of users.每个索引的开销对于大量用户来说会变得很重要。

One possible exception might be if different users were going to store documents with very different fields, but even then you'd be better off with a small number of indices rather than one per user.一个可能的例外可能是,如果不同的用户要存储具有非常不同的字段的文档,但即便如此,您最好使用少量索引而不是每个用户一个。

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

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