将每个文档与Elasticsearch中的搜索参数要满足的功能相关联 [英] Associating each document with a function to be satisfied by search parameters in Elasticsearch

查看:40
本文介绍了将每个文档与Elasticsearch中的搜索参数要满足的功能相关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Elasticsearch中,我可以将每个文档与一个(不同的)函数相关联,该函数必须由我在搜索中提供的参数才能满足,以便在该搜索中返回?

In Elasticsearch, can I associate each document with a (different) function that must be satisfied by parameters I supply on a search, in order to be returned on that search?

我特别想使用的特定功能包括循环,某种简单的分支(if-statement of switch-statement),类似数组的数据结构,字符串比较和简单的布尔运算符.

The particular functions I would particularly like to use involve a loop, some kind of simple branching (if-statement of switch-statement), an array-like data structure, strings comparisons, and simple boolean operators.

推荐答案

此处有两个主题演讲:

在查询时:-如果您希望塑造相关性功能,即每个文档的实际相关性得分,则可以使用

At query time: - If your looking to shape the relevancy function, meaning the actual relevancy score of each document, you could use a script score query. - If you're only looking to filter out unwanted documents, you could use a script query that allows you to do just that.

通过这两种解决方案,您都可以计算出分数,将传入的查询参数与现有的先前索引值进行比较.

Both of those solutions enables you to compute a score comparing incoming query parameters against existing previously indexed values.

请注意,在查询时使用脚本会导致内存使用率增加和性能问题.

Take note that usage of scripts at query time can lead to increased memory usage and performance issues.

  • Elastic can also handle a second batch of filtering rules that are applied to the actual query result in the form of a post filter. Can come in handy sometime if you're not in a position of stream processing the output at API view level.

在索引时间:

  • 有一种叫做脚本字段,可让您存储一个函数,该函数根据其他字段的值和传入的查询参数来计算结果.考虑到它们是在索引时间分配的,因此它们确实非常强大.我认为它们可能就是您想要的.如果我不将这些字段值与查询参数进行比较,则不会使用这些字段.原因是我希望索引过程精简且快速,因此我倾向于在实际批量索引查询上游的流级别计算这些类型的值.
  • There is such a thing called script fields that allows you to store a function that computes a result based on other fields value and incoming query parameters. they can be really powerful given the fact that they are assigned at index time. I think they might be what you are looking for. I would not be using those if i weren't to have those field values compared against query params. Reason is that I like my index process to be lean and fast so I tend to compute those kinds of values at stream level, in upstream from the actual bulk indexing query.

尽管很方便,但结合使用常规查询和过滤器,可能可以实现那些自定义脚本的结果.在每个版本中,elasticsearch团队都会添加新的查询和字段类型,使您可以通过脚本化查询来完成自己的工作,从而消除内存耗尽的风险.一个很好的例子是排名要素数据类型最近在7.x版本中引入.

Although convenient, those custom scripts results are likely to be achievable with a combination of regular queries and filters. In each release, the elasticsearch teams is adding new query and field types that let you do what you use to do via scripted queries whiteout the risk of blowing out you memory. a good example of this is the rank feature datatype recently introduced in the 7.x release.

为您提供的一条建议.将您的Elasticsearch服务视为数据层中的常规API.这样,您可以在实际调用弹性之前进行查询处理,并且可以从实际弹性结果进行数据处理.如果您真的不适合您的业务规则,那将是您的最后选择.如果您还有任何疑问,请随时与我联系.一切顺利.

A piece of advice for you. think of your elasticsearch service as a regular API in your datalayer. As such you can do query processing before the actual call to elastic and you can do data processing from the actual elastic results. If you really can't fit your business rules in there, that would be your last resort. Fell free to contact me if you still have any questions. All the best.

这篇关于将每个文档与Elasticsearch中的搜索参数要满足的功能相关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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