2016-02-04 63 views
0

我有一個查詢的作品,其中包括一些過濾器:Elasticsearch must_not過濾掉不與一大束值

{ 
     "from": 0, 
     "query": { 
      "function_score": { 
       "query": { 
        "filtered": { 
         "filter": { 
          "bool": { 
           "must": [ 
            { 
             "term": { 
              "idpais": [ 
               115 
              ] 
             } 
            }, 
            { 
             "term": { 
              "tipo": [ 
               1 
              ] 
             } 
            } 
           ], 
           "must_not": [ 
            { 
             "term": { 
              "idregistro": [ 
               5912471, 
               3433876, 
               9814443, 
               11703069, 
               6333176, 
               8288242, 
               9924922, 
               6677850, 
               11852501, 
               12530205, 
               4703469, 
               12776479, 
               12287659, 
               11823679, 
               12456304, 
               12777457, 
               10977614, 
               ... 
              ] 
             } 
            } 
           ] 
          } 
         }, 
         "query": { 
          "bool": { 
           "should": [ 
            { 
             "match_phrase": { 
              "area": "Coordinator" 
             } 
            }, 
            { 
             "match_phrase": { 
              "company": { 
               "boost": 5, 
               "query": "IBM" 
              } 
             } 
            }, 
            { 
             "match_phrase": { 
              "topic": "IT and internet stuff" 
             } 
            }, 
            { 
             "match_phrase": { 
              "institution": { 
               "boost": 5, 
               "query": "University of my city" 
              } 
             } 
            } 
           ] 
          } 
         } 
        } 
       }, 
       "script_score": { 
        "params": { 
         "idpais": 115, 
         "idprovincia": 0, 
         "relationships": [] 
        }, 
        "script_id": "ScoreUsuarios" 
       } 
      } 
     }, 
     "size": 24, 
     "sort": [ 
      { 
       "_script": { 
        "order": "desc", 
        "script_id": "SortUsuarios", 
        "type": "number" 
       } 
      } 
     ] 
    } 

的must_not濾波器具有一大束值,以排除(大約200個值),但它看起來像elasticsearch忽略這些值,它包含在結果集中。如果我嘗試僅設置一些值(10到20個值),那麼elasticsearch會應用must_not過濾器。

在過濾器中存在一定數量的限制嗎?是否存在某種方法從查詢中刪除大量結果?

+0

你有沒有使用術語(注意字母'')而不是'term'沒有s? – CodeNotFound

+0

@CodeNotFound謝謝。謝謝,我從來沒有注意到關於「條款」指令 –

+0

它工作:D? – CodeNotFound

回答

0

terms query用於傳遞值的列表,而不是term query。您必須在您的must filter中使用它,如下所示。

{ 
    "query": { 
    "terms": { 
     "field_name": [ 
      "VALUE1", 
      "VALUE2" 
     ] 
    } 
    } 
} 
+0

,但問的問題是不匹配的值... –

+0

正如上面的問題所述,「term」查詢被用於匹配值列表。我們需要使用terms來代替 – Richa

+0

ok ..有你的觀點..!它只是查詢的一部分..不是查詢。但正如你已經給出它將列出那些匹配條件的記錄?對??而不是那些不符合這些條款的呢? –