使用Java自动完成,Redis,Elastic Search,Mongo

使用Java自动完成,Redis,Elastic Search,Mongo

问题描述:

我必须实现一个自动填充功能,该功能必须包含500,000个以上的名称,以后可能会增加到400万个以上的名称.

I have to implement an autocomplete with over 500,000 names which may later increase to over 4 million names.

后端是使用Spring的Java REST Web服务调用.我应该使用 MongoDB Redis Elasticsearch 来存储和查询/搜索名称吗?

Backend is a java REST web service call using Spring. Should I use MongoDB, Redis or Elasticsearch for storing and querying/searching the names?

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

It's a critical search use case, and MongoDB and Redis are perfect for key-based lookups and not use for Search purposes, while Elasticsearch is a distributed search engine, built specifically for such use-case.

在选择系统之前,您应该了解功能部件的内部工作原理,并且在选择它的考虑因素以下.

Before choosing the system, you should know how your feature works internally And below the consideration for selecting it.

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

一些功能要求.

  1. 自动完成应如何显示,对名称进行前缀,前缀搜索?
  2. 在向用户显示自动完成结果之前,应最少输入多少个字符.
  3. 上述要求可以多久更改一次.

Elasticsearch在倒排索引中建立索引的文档并在 代币匹配(可以轻松自定义以适合业务 要求),因此搜索速度超快. Redis和MongoDB是 内部不具有此结构,因此不应用于此 用例.您不应该对选择Elasticsearch存有任何疑问 这些来实现自动完成功能.

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.

由于自动填充是基本搜索功能之一,因此博客,您应该阅读该博客以了解Elasticsearcg提供的不同方法及其取舍.

As autocomplete is one of the essential search features, there is an excellent blog, which you should read to understand different approaches offered by Elasticsearcg and their trade-off.