Elasticsearch-使用条件衰减函数搜索多个索引 [英] Elasticsearch - search across multiple indices with conditional decay function
问题描述
我试图用一个查询搜索多个索引,但仅将高斯衰减函数应用于存在于其中一个索引上的字段.
I'm trying to search across multiple indices with one query, but only apply the gaussian decay function to a field that exists on one of the indices.
我正在通过elasticsearch-api gem运行此部分,并且该部分工作正常.
I'm running this through elasticsearch-api gem, and that portion works just fine.
这是我在奇迹中运行的查询.
Here's the query I'm running in marvel.
GET episodes,shows,keywords/_search?explain
{
"query": {
"function_score": {
"query": {
"multi_match": {
"query": "AWESOME SAUCE",
"type": "most_fields",
"fields": [ "title", "summary", "show_title"]
}
},
"functions": [
{ "boost_factor": 2 },
{
"gauss": {
"published_at": {
"scale": "4w"
}
}
}
],
"score_mode": "multiply"
}
},
"highlight": {
"pre_tags": ["<span class='highlight'>"],
"post_tags": ["</span>"],
"fields": {
"summary": {},
"title": {},
"description": {}
}
}
}
该查询对情节索引非常有用,因为它具有高斯函数的published_at字段,以发挥其魔力.但是,当跨所有索引运行时,它对于显示和关键字失败(对于情节仍然成功).
The query works great for the episodes index because it has the published_at field for the gauss func to work its magic. However, when run across all indices, it fails for shows and keywords (still succeeds for episodes).
如果published_at字段存在或在单集索引上,是否可以运行条件高斯衰减函数?
Is it possible to run a conditional gaussian decay function if the published_at field exists or on the single episodes index?
我愿意探索替代方法(例如,对每个索引运行单独的查询,然后合并结果),但是我认为单个查询在性能方面是最好的.
I'm willing to explore alternatives (i.e. run separate queries for each index and then merge the results), but thought a single query would be the best in terms of performance.
谢谢!
推荐答案
您可以添加过滤器,以将那些高斯衰减函数仅应用于文档的子集:
You can add a filter to apply those gaussian decay function only to a subset of documents:
{
"filter": {
"exists": {
"field": "published_at"
}
}
"gauss": {
"published_at": {
"scale": "4w"
}
}
}
对于没有该字段的文档,您可以返回0分:
For docs that don't have the field you can return a score of 0:
{
"filter": {
"missing": {
"field": "published_at"
}
}
"script_score": {
"script": "0"
}
}
这篇关于Elasticsearch-使用条件衰减函数搜索多个索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!