Elasticsearch、Nest 和 Lucene.net

Elasticsearch, Nest and Lucene.net

我知道 Elasticsearch 基于 Lucene,但我想知道 Elasticsearch 是否给我开发搜索引擎而不是直接使用 Lucene.Net 编码带来任何好处。抱歉,如果问题有点简单,但在搜索创建搜索引擎的可能性后我感到困惑。

我找到了更多简单 lucene.net 搜索的示例,但 Elasticsearch 和 Nest 的示例并不多。另一个问题是 Nest 和 Elasticsearch 之间到底有什么区别?他们是一样的吗?

如果有人在这里给我一些启发,也许有一个很好的样本,我很感激。我需要的是?简单,快速和快速的搜索引擎。什么是最好的选择?任何其他替代方案也可以,但只能是 .net(c# 或 vb)谢谢。

Lucene 和 Elasticsearch 是两个完全不同的 类 应用程序。

Lucene 是一个使用基本的 Lucene 查询语言实现倒排索引并对其进行搜索和排名的库。它不是一个独立的应用程序,您可以 运行 和使用(索引文档、搜索文档、检索文档,...)。

Elasticsearch 是一个构建在 Lucene 之上的分布式服务器。 Elasticsearch 为您提供了一个很好的 REST API,您可以使用它来索引、搜索和检索您的文档。它还实现了一种查询语言,其功能远远超出了 Lucene 自身所能完成的功能。它也是一个分布式服务器 - 这意味着您可以在多台机器上将 Elasticsearch 服务器作为集群启动,它会自动负责在它们之间分发和复制数据。

同样,Solr也是一个建立在Lucene之上的搜索引擎。

所以这实际上取决于您希望实现的目标。如果它只是实现嵌入现有应用程序的全文搜索功能,那么 Lucene 可能就是您所需要的。另一方面,如果您想为您的网站实施一个关于电影的电影搜索引擎,那么您最好使用 Elasticsearch 或 Solr。

Lucene

Lucene and the .NET port, Lucene.Net, is a search engine library for supporting full-text search in an application; it builds an inverted index based on the Document (and the fields within the Document) that you feed it to support full-text search. An example of this is search within the Nuget Gallery source,其中 nuget 包及其属性被转换为文档以传递给 Lucene。倒排索引跨文件存储在一个目录中。

弹性搜索

Elasticsearch is a distributed search engine that uses Lucene under the covers - An Elasticsearch cluster can be made up of one or more nodes, where each node can contain a number of shards and replicas; each shard is a complete Lucene index. Having such infrastructure enables fast performance and allows horizontal scaling to handle search across a large amount of data since you are no longer limited by the constraints of a single Lucene index on a single machine. In addition you can achieve high availability with fault tolerance and disaster recovery since data can be replicated across shards meaning there is no single point of failure. An example of Elasticsearch with NEST is up on my blog.

使用哪个?

好吧,这取决于您的用例(几乎总是这样,对吧?);如果您的应用程序是安装到机器上的应用程序并且所有数据都保存在本地,您可能会决定在应用程序中使用 Lucene 库并将索引目录保存到本地磁盘。类似地,如果您有一个简单的 Web 应用程序,该应用程序在具有 少量 用户的单个服务器上运行,那么使用 Lucene 可能也是一个明智的选择。另一方面,如果您的应用程序在网络场中的多台机器上运行并且需要搜索功能,那么使用像 Elasticsearch 这样的分布式搜索引擎是个好主意。

Elasticsearch 的扩展性如何?早在 2013 年,Github was using Elasticsearch to index 2 billion documents 即站点上每个存储库中的所有代码文件 - 跨越 44 个独立的 Amazon EC2 实例,每个实例都有 2 TB 的临时 SSD 存储,总共提供 30 TB 的主要数据。 Whosebug 还使用 Elasticsearch 来支持此站点上的搜索 (也许开发人员可以评论一些 figures/metrics?)