2017-08-11 73 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") 
        ) 
       ) 
      ) 
     ) 
    ) 
);