2013-07-18 104 views
3

我需要修改此查詢,以便彈性搜索而不是給它一個分數。我希望我的自定義篩選分數是唯一給予任何結果得分的東西。我該如何做到這一點?在彈性搜索中過濾器查詢無分數

每個記錄只應每有一個得分爲0,100,或1000

{ 
    "size":50, 
    "from":0, 
    "query" : { 
    "custom_filters_score" : { 
     "query" : { 
     "filtered" : { 
      "query" : { 
      "bool" : { 
       "must" : [ 
       {"term":{"type":"alpha"}}, 
       {"field":{"sector":"exists"}}, 
       {"field":{"sector.sub":"exists"}}, 
       {"field":{"alpha_sector.sub.categories":"second"}}, 
       {"field":{"beta_sector.sub.columns":"first"}}, 
       {"term":{"beta_type":"beta"}}, 
       {"term":{"area":"624"}} 
       ] 
      } 
      }, 
      "filter" : { 
      "or" : [ 
       { 
       "and" : [ 
        {"term":{"area":"624"}}, 
        {"term":{"start":"07242013"}} 
       ] 
       }, 
       { 
       "and" : [ 
        {"term":{"area":"624"}}, 
        {"term":{"start":"blank"}} 
       ] 
       } 
      ] 
      } 
     } 
     }, 
     "filters" : [ 
     {"filter":{"term":{"resource":5726}}, "boost":"1000"}, 
     {"filter":{"term":{"alpha_resource":5726}}, "boost":"100"} 
     ], 
     "score_mode":"sum" 
    } 
    } 
} 

回答

3

我不太清楚你正試圖在這裏實現

  {"field":{"sector":"exists"}}, 
      {"field":{"sector.sub":"exists"}}, 

但在一般的東西,如果您不希望部分查詢影響分數,請將其作爲過濾條件。這也將是更好地使用「布爾」與「術語」過濾器而不是「和」 /「或」 /「而不是」

{ 
    "size":50, 
    "from":0, 
    "query" : { 
    "custom_filters_score" : { 
     "query" : { 
     "filtered" : { 
      "query" : { 
      "match_all": {} 
      }, 
      "filter" : { 
      "bool" : { 
       "must" : [ 
       {"term":{"type":"alpha"}}, 
       {"query":{"field":{"sector":"exists"}}}, 
       {"query":{"field":{"sector.sub":"exists"}}}, 
       {"query":{"field":{"alpha_sector.sub.categories":"second"}}}, 
       {"query":{"field":{"beta_sector.sub.columns":"first"}}}, 
       {"term":{"beta_type":"beta"}}, 
       {"term":{"area":"624"}} 
       ], 
       "should" : [ 
       { 
        "bool" : { 
        "must" : [ 
         {"term":{"area":"624"}}, 
         {"term":{"start":"07242013"}} 
        ] 
        } 
       }, 
       { 
        "bool" : { 
        "must": [ 
         {"term":{"area":"624"}}, 
         {"term":{"start":"blank"}} 
        ] 
        } 
       } 
       ] 
      } 
      } 
     } 
     }, 
     "filters" : [ 
     {"filter":{"term":{"resource":5726}}, "boost":"1000"}, 
     {"filter":{"term":{"alpha_resource":5726}}, "boost":"100"} 
     ], 
     "score_mode":"total" 
    } 
    } 
} 
+0

感謝您的回覆,我對實際字段進行了模糊處理,因爲它們非常敏感,因此查詢的數據部分可能無法完成的感覺,但結構是準確的,我會給這個測試wh我從其他正在工作的東西中爬出來,並讓它知道它是否有效! – Aristata

+0

這就像一個魅力,非常感謝你! – Aristata

+0

嗨@imotov - 你介意看看[這個問題](http://stackoverflow.com/questions/37372951/elasticsearch-query-time-boosting-produces-result-in-inadequate-order?noredirect=1#comment62264775_37372951 )我的嗎? – BentCoder