小编典典

elasticsearch函数中对过滤器的嵌套支持

elasticsearch

我目前正在尝试在NEST中实现“ function_score”查询,其功能仅在过滤器匹配时才适用。

看起来FunctionScoreFunctionsDescriptor似乎还不支持添加过滤器。是否会在不久的将来添加此功能?

这是我想要实现的一个超基本示例:

  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
    }

我目前正在使用Elasticsearch v1.1.0和NEST v1.0.0-beta1预发行版。

谢谢!


阅读 388

收藏
2020-06-22

共1个答案

小编典典

它已经实现:

_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))));
2020-06-22