2017-10-10 63 views

回答

1

您可以使用boolterms查詢做到這一點象下面這樣:

{ 
    "query": { 
     "bool": { 
      "must": [ 
       { 
        "terms": { 
         "Country": [ 
         "USA", 
         "UK" 
         ] 
        } 
       }, 
       { 
        "terms": { 
         "Expertise": [ 
         "Botany", 
         "Physics" 
         ] 
        } 
       } 
      ] 
     } 
    } 
} 

在另一方面,你只能使用bool查詢做到這一點:

{ 
    "query": { 
     "bool": { 
      "must": [ 
       { 
        "bool": { 
         "should": [ 
          { 
           "term": { 
           "Country": { 
            "value": "USA" 
           } 
           } 
          }, 
          { 
           "term": { 
           "Country": { 
            "value": "UK" 
           } 
           } 
          } 
         ] 
        } 
       }, 
       { 
        "bool": { 
         "should": [ 
          { 
           "term": { 
           "Expertise": { 
            "value": "Botany" 
           } 
           } 
          }, 
          { 
           "term": { 
           "Expertise": { 
            "value": "Physics" 
           } 
           } 
          } 
         ] 
        } 
       } 
      ] 
     } 
    } 
} 

但是,請看看documentation在問任何其他問題之前。也許,你可能會發現一個較短的查詢。

+0

謝謝。第二個選項奏效。 –

相關問題