2017-06-13 85 views
0

我需要一個elasticsearch查詢,但它必須包含多個where和orwhere子句,像這樣;Elasticsearch多個where和orwhere查詢

SELECT * FROM圖片WHERE((寬度= 400和高度= 300)OR(寬度= 800和高度= 600))AND狀態= 1 AND刪除= 0

謝謝。

+0

使用布爾查詢:https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html 必須是AND的子句,並且OR子句爲OR –

回答

0

使用此查詢

{ 
 
    "query": { 
 
    "bool": { 
 
     "must": [ 
 
     { 
 
      "match": { 
 
      "status": 1 
 
      } 
 
     }, 
 
     { 
 
      "match": { 
 
      "deleted": 0 
 
      } 
 
     } 
 
     ], 
 
     "should": [ 
 
      { 
 
      "bool": { 
 
       "must": [ 
 
       { 
 
        "match": { 
 
        "width": "400" 
 
        } 
 
       }, 
 
       { 
 
        "match": { 
 
        "height": "300" 
 
        } 
 
       } 
 
       ] 
 
      } 
 
      }, 
 
      { 
 
      "bool": { 
 
       "must": [ 
 
       { 
 
        "match": { 
 
        "width": "800" 
 
        } 
 
       }, 
 
       { 
 
        "match": { 
 
        "height": "600" 
 
        } 
 
       } 
 
       ] 
 
      } 
 
      } 
 
     ] 
 
    } 
 
    } 
 
}

+0

非常感謝 –