如何在弹性搜索中应用过滤器? [英] How are filters applied in Elastic Search?

查看:130
本文介绍了如何在弹性搜索中应用过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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.

这篇关于如何在弹性搜索中应用过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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