[英]Combine range and must filter in elasticsearch
i have some problems with ElasticSearch. 我在ElasticSearch上遇到了一些问题。 I am a newbie, so that is normal.
我是新手,所以很正常。 My need is to configure the search on my website.
我需要在我的网站上配置搜索。 I have some videos and there are some filters to decrease the shown results.
我有一些视频,并且有一些过滤器可以减少显示的结果。 I have exact match filters, but also range filters.
我有精确匹配过滤器,还有范围过滤器。
So my problem is to combine the search keyword with those filters, based on what the user is searching for. 因此,我的问题是根据用户要搜索的内容将搜索关键字与这些过滤器组合在一起。
I have made so far to combine the searched keyword with the range filters, but if there is set an exact match filter i have no idea how to do it. 到目前为止,我已经将搜索关键字与范围过滤器组合在一起,但是如果设置了精确匹配过滤器,我不知道该怎么做。
Here is how the parameters go now to Elasticsearch: 现在将参数传递给Elasticsearch的方法如下:
[body] => Array
(
[query] => Array
(
[filtered] => Array
(
[query] => Array
(
[multi_match] => Array
(
[query] => messi
[fields] => Array
(
[0] => title
[1] => duration
[2] => id_category
[3] => id_tag
)
[fuzziness] => 0.5
)
)
[filter] => Array
(
[range] => Array
(
[duration] => Array
(
[gte] => 0
[lte] => 300
)
)
)
)
)
)
How should it look like if i have filter to show me only the videos, matching the keyword "messi" with duration between 0 and 300 seconds in some category ? 如果我有过滤器仅向我显示视频,并且在某些类别中将持续时间在0到300秒之间的关键字“ messi”与之匹配,该怎么办?
Thnks in advice ! 谢谢!
Have a look at the Bool Query . 看看Bool Query 。 I would suggest you put your multi match query in the must part and move your filters to the (quite obvious) filter part.
我建议您将多匹配查询放在must部分中,然后将过滤器移至(非常明显的)过滤器部分。 Because of that, ES will calculate a relevance score based on the multi match but combine it with cacheability of the filters.
因此,ES将基于多重匹配计算相关性得分,但会将其与过滤器的可缓存性结合起来。 A short example:
一个简短的例子:
<?php
$query = [
'body' => [
'query' => [
'bool' => [
'must' => [
[
'multi_match' => []
],
...
],
'filter' => [
[
'range' => []
],
...
]
]
]
]
];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.