使用 java、Redis、弹性搜索、Mongo 自动完成

Autocomplete with java , Redis, Elastic Search , Mongo

我必须实现一个包含超过 500,000 个名称的自动完成功能,以后可能会增加到超过 400 万个名称。

后端是使用 Spring 的 java REST 网络服务调用。我应该使用 MongoDBRedis 还是 Elasticsearch 进行存储和 querying/searching名字?

这是一个关键的搜索用例,MongoDB 和 Redis 非常适合基于键的查找,而不是用于搜索目的,而 Elasticsearch 是一个分布式搜索引擎,专为此类用例构建。

在选择系统之前,您应该了解您的功能在内部是如何工作的以及下面选择它的考虑因素。

您的功能的非功能性要求

  1. 每秒搜索查询总数 (QPS) 是多少?
  2. 您更新文档的频率(即您示例中的名称)。
  3. 更新后出现在搜索结果中的名称后的 SLA 是什么?
  4. 搜索结果的 SLA。

一些功能需求。

  1. 名称的前缀、中缀搜索应该是什么样子的?
  2. 用户在显示自动完成结果之前至少应输入多少个字符。
  3. 上述要求更改的频率。

Elasticsearch indexed documents in the inverted index and works on tokens match(which can be easily customized to suit business requirements), hence super fast in searching. Redis and MongoDB are not having this structure internally and shouldn't be used for this use-case. You shouldn't have any doubt about choosing Elasticsearch over these to implement Autocomplete.

您可以使用 RediSearch (https://oss.redislabs.com/redisearch/)。它是一个自由文本搜索引擎,作为 Redis 模块构建在 Redis 之上。它还具有自动完成功能。