如何在弹性搜索中应用过滤器?

编程入门 行业动态 更新时间:2024-10-18 21:19:29
本文介绍了如何在弹性搜索中应用过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在ES中是在查询之前应用的过滤器?

In ES are filters applied before the query?

例如,我做的是一个非常慢的模糊搜索,但我只是在一个小日子范围。例如,您可以看下面(PHP):

Say, for example, I am doing a really slow fuzzy search but I am only doing it on a small date range. For an example you can look below (PHP):

$res=$client->search(array('index' => 'main', 'body' => array( 'query' => array( 'bool' => array( 'should' => array( array('wildcard' => array('title' => '*123*')), ) ) ), 'filter' => array( 'and' => array( array('range' => array('created' => array('gte' => date('c',time()-3600), 'lte' => date('c',time()+3600)))) ) ), 'sort' => array() )));

在尝试更慢的搜索之前,是否应用过滤器?

Will the filter be applied before trying that slower search?

逻辑将规定过滤器运行然后查询,但我想确定。

Logic would dictate that filters are run and then the query but I would like to be sure.

推荐答案

如果您使用过滤的 -query,那么过滤器将在文档评分之前应用。

If you use the filtered-query, then filters will be applied before documents are scored.

这通常会加快事情相当多了但是,模糊查询仍然会使用输入来构建较大的查询,而不考虑过滤器。

This will generally speed things up quite a lot. However, the fuzzy query will still be using the input to build a larger query regardless of the filters.

当您使用过滤器右边的搜索对象,那么查询将首先运行而不考虑过滤器,那么文档将被从命中

When you use filter right on the search object, then the query will first run without respecting the filter, then documents will be filtered out of the hits - whereas facets will remain unfiltered.

因此,您几乎总是使用过滤的 -query,至少在您没有使用方面。

Therefore, you should almost always use the filtered-query, at least when you are not using facets.

更多推荐

如何在弹性搜索中应用过滤器?

本文发布于:2023-11-22 20:28:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1618909.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:滤器   用过   中应   弹性   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!