Autocomplete with java , Redis, Elastic Search , Mongo

柔情痞子 提交于 2020-04-07 06:56:12

问题


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

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


回答1:


This is a very important search use case and MongoDB and Redis are very good 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 choosing it.

non-functional requirements for your feature

  1. What would be the total no of search queries per second (QPS)?
  2. How frequently you would be updating the documents(ie names in your example).
  3. What is the SLA after names in updated and coming in the search result?
  4. SLA for your search results.

Some functional requirements.

  1. How autocomplete should look like, prefix, infix search on names?
  2. Minimum how many character user should type, before showing them the autocomplete results.
  3. How frequently the above requirements can change.

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 And you shouldn't have any doubt to choose Elasticsearch over these to implement Autocomplete.

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




回答2:


You can use RediSearch (https://oss.redislabs.com/redisearch/). Its a free text search engine build on top of Redis as a RedisModule. It also has an auto complete feature.



来源:https://stackoverflow.com/questions/60584099/autocomplete-with-java-redis-elastic-search-mongo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!