2017-08-31 46 views
0

我正在尋找一個等同於下面的僞代碼:Elasticsearch相當於其中x = 1和(y = 2或y = 3)

SELECT id, age         // works 
    FROM students         // works 
WHERE firstname = 'John'      // works 
    AND gender = 'm'        // works 
    AND (lastname = 'Doe' OR lastname = 'Wayne') // no idea 

我當前的代碼:

{ 
    // ... 
    query: { 
     bool: { 
      must: [ 
       { match: { firstname: 'John' }}, 
       { match: { gender: 'm' }}, 
      ] 
     } 
    } 
} 

我正在努力與OR

任何想法?

提前致謝!

+1

看一看這個https://www.elastic.co/guide/en/elasticsearch/guide/current/_finding_multiple_exact_values。 html –

回答

1

嘗試:

{ match: { lastname: /^(Doe|Wayne)$/ }} 
+0

我很驚訝這項工作,因爲匹配查詢不支持正則表達式。 – Val

1

試試這個:

{ 
    // ... 
    query: { 
     bool: { 
      must: [ 
       { match: { firstname: 'John' }}, 
       { match: { gender: 'm' }}, 
       { 
        bool: { 
        minimum_should_match: 1, 
        should: [ 
         { match: { lastname: 'Doe' }}, 
         { match: { lastname: 'Wayne' }} 
        ] 
        } 
       } 
      ] 
     } 
    } 
} 
相關問題