在ElasticSearch中保存用户搜索查询的最佳方法? [英] Best way to save users search queries in ElasticSearch?

查看:91
本文介绍了在ElasticSearch中保存用户搜索查询的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用ElasticSearch和SQL数据库的应用程序.那么,保存用户搜索查询并显示统计信息(如最受欢迎的请求)的最佳方法是什么?简单的方法是保存在SQL数据库中并计数.但是,也许在ElasticSearch中内置了一些技术?

I am developing application that uses ElasticSearch and SQL database. So, what is the best way to save users search queries and show statistics like what are the most popular requests? The simply way is to save in SQL database and count. But maybe there are some technique built in ElasticSearch?

推荐答案

您可以通过在ES群集中​​创建第二个索引来做到这一点.当用户通过您的应用程序提交搜索时,您将执行两个步骤.

You could do this by creating a second index in your ES cluster. When a user submits a search through your application you perform two steps.

  1. 将搜索作为查询提交给Elasticsearch以获取正常搜索行为.
  2. 使用用户提供的搜索字词向集群提交索引请求.

有了已提交的所有搜索词的第二个索引,您可以做很多事情.对于您的情况,您可以像在SQL中一样具有一个计数"字段,随着越来越多的人搜索该术语,该字段就会递增.另一个很好的用例是google样式推荐的术语.您的UI可以在每次按键时使用输入的文本提交搜索请求,并使用先前搜索到的字词填充下拉列表.您甚至可以通过添加用户字段并过滤掉不是来自该特定用户的结果来个性化此设置.

With a second index of all search terms that have been submitted you can do a number of neat things. For your case, you can have a 'count' field just like in SQL that you increment as more people search for that term. Another great use case is a google style recommended terms. Your UI can submit a search request with the entered text on each key press and populate a drop down with hits from the previously searched terms. You can even personalize this by adding a user field and filtering out results not from that particular user.

要记住的是,ElasticSearch可以用作主要和辅助数据存储.我总是建议您只将您愿意丢失的数据(例如搜索历史记录)保留为主数据.将您的系统关键数据保存在SQL之类的更传统的数据存储中,这样就可以在发生任何错误时轻松地进行备份和还原!

The thing to keep in mind is that ElasticSearch can be used as both a primary and secondary data store. I always suggest that you only keep data you are willing to lose (like search history) as primary data though. Keep your system critical data in a more traditional data store like SQL, that way it is easy to back up and restore if anything ever goes wrong!

这篇关于在ElasticSearch中保存用户搜索查询的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆