我必须实现超过 500,000 个名字的自动完成,这些名字以后可能会增加到超过 400 万个名字。
后端是使用 Spring 的 Java REST Web 服务调用。我应该使用 MongoDB、 Redis还是 Elasticsearch 来存储和查询/搜索名称?
我ElasticSearch在一个网站中使用,我从MongoDB.
def postToEs(self):
"""
put data to the elasticsearch
"""
es = Elasticsearch()
cursor = self.getMongoData()
for document in cursor:
esdoc={}
esdoc["category"] = document.get("category")
esdoc["description"] = document.get("description")
esdoc["title"] = document.get("title")
esdoc["link"] = document.get("link")
esdoc["state"] = document.get("state")
esdoc_id = esdoc["link"]
es.index(
index = 'news',
doc_type = 'allnews',
id = esdoc_id,
body = json.dumps(esdoc)
)
Run Code Online (Sandbox Code Playgroud)
这很好用。但目前我必须在该state字段中搜索elasticsearch. 目前,如果我搜索New York它的条目也会给出New Hampshire. 我找到了这个链接,并看到了我需要添加mapping到数据中的elasticsearch 文档。我的问题是如何在当前场景中为数据添加映射?或者有什么更好的方法吗?