2017-08-11 75 views
0

我想建立使用使用DSL语法以下查询:过滤功能评分与鸟巢

GET /_search 
    { 
     "query": { 
     "function_score": { 
      "filter": { 
      "term": { "city": "Barcelona" } 
      }, 
      "functions": [ 
      { 
       "filter": { "term": { "features": "wifi" }}, 
       "weight": 1 
      }, 
      { 
       "filter": { "term": { "features": "garden" }}, 
       "weight": 1 
      }, 
      { 
       "filter": { "term": { "features": "pool" }}, 
       "weight": 2 
      } 
      ], 
      "score_mode": "sum", 
     } 
     } 
    } 

但是似乎使用NEST客户端时,有一个在function_score没有filter选项。我可以确认查询在弹性工作。

回答

2

我不确定您定位的是哪个版本的Elasticsearch,但自从Elasticsearch 2.0,when queries and filters were merged以来,在function_score查询中没有filter属性。 NEST公开了Elasticsearch API中可用的内容,因此该属性在NEST 1.x中可用,但在任何更高版本中都不可用。

Filters on individual functions exist

var response = client.Search<object>(s => s 
    .Query(q => q 
     .FunctionScore(fs => fs 
      .Functions(fu => fu 
       .Weight(w => w 
        .Weight(1) 
        .Filter(wf => wf 
         .Term("features", "pool") 
        ) 
       ) 
      ) 
     ) 
    ) 
);