2016-06-07 140 views
0

我有3個字段,例如,field1field2field3。 我需要這樣創造的東西:ElasticSearch帶過濾器或布爾查詢

if { field1 != 1 AND field2 != 1 AND field3 != 1 } OR if { field1 != 2 AND field2 != 2 AND field3 != 2 }

我試圖通過兩個boolquery做到這一點,但它返回我什麼。 然後我試圖將這些查詢包裝到一個filter中,但它總是引發我異常no query defined for [filter]]。但是我的boolquery這個過濾器總是空的,它什麼都沒有返回。我可以添加一些東西到這個boolquery檢索所有結果,然後過濾它們?或者我需要以另一種方式創建查詢,但是如何?

+0

您運行的是什麼版本的ES的? – Val

+0

@Val ES版本1.5.2 – Squeez

回答

1

這裏是你如何能做到這

{ 
    "query": { 
    "filtered": { 
     "filter": { 
     "or": [ 
      { 
      "and": [ 
       { 
       "not": { 
        "term": { 
        "field1": "1" 
        } 
       } 
       }, 
       { 
       "not": { 
        "term": { 
        "field2": "1" 
        } 
       } 
       }, 
       { 
       "not": { 
        "term": { 
        "field3": "1" 
        } 
       } 
       } 
      ] 
      }, 
      { 
      "and": [ 
       { 
       "not": { 
        "term": { 
        "field1": "2" 
        } 
       } 
       }, 
       { 
       "not": { 
        "term": { 
        "field2": "2" 
        } 
       } 
       }, 
       { 
       "not": { 
        "term": { 
        "field3": "2" 
        } 
       } 
       } 
      ] 
      } 
     ] 
     } 
    } 
    } 
} 
+0

這對我不起作用。它沒有找到任何東西。也許這是因爲我使用1.5.2 ES? – Squeez

+0

@Squeez你能分享你的索引映射以及你試圖否定的實際值嗎? (我猜這不是1和2)。 –

相關問題