弹性搜索在功能核心功能中支持滤镜 [英] elasticsearch nest support of filters in functionscore function

查看:96
本文介绍了弹性搜索在功能核心功能中支持滤镜的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在NEST中实现一个function_score查询,功能仅在过滤器匹配时才应用。

I am currently trying to implement a "function_score" query in NEST, with functions that are only applied when a filter matches.

它看起来不像FunctionScoreFunctionsDescriptor还支持添加过滤器。这个功能是否会在任何时候添加?

It doesn't look like FunctionScoreFunctionsDescriptor supports adding a filter yet. Is this functionality going to be added any time soon?




以下是我想要实现的一个超级基本示例:



Here's a super basic example of what I'd like to be able to implement:


  1. 运行基本分数的ES查询

  2. 查看功能列表,并将其添加到筛选器的第一个分数匹配



"function_score": {
    "query": {...},  // base ES query
    "functions": [
        {
            "filter": {...},
            "script_score": {"script": "25"}
        },
        {
            "filter": {...},
            "script_score": {"script": "15"}
        }      
    ],
    "score_mode": "first",  // take the first script_score where the filter matches
    "boost_mode": "sum"  // and add this to the base ES query score
}

谢谢!

推荐答案

已经实现:

_client.Search<ElasticsearchProject>(s => 
            s.Query(q=>q
                .FunctionScore(fs=>fs.Functions(
                    f=>f
                        .ScriptScore(ss=>ss.Script("25"))
                        .Filter(ff=>ff.Term(t=>t.Country, "A")),
                    f=> f
                        .ScriptScore(ss=>ss.Script("15"))
                        .Filter(ff=>ff.Term("a","b")))
                .ScoreMode(FunctionScoreMode.first)
                .BoostMode(FunctionBoostMode.sum))));

这篇关于弹性搜索在功能核心功能中支持滤镜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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