2017-02-23 45 views
1
 
{ 
    "query": 
    { 
    "bool": 
    { 
     "should": [ 
     { 
      "has_child": { 
      "inner_hits":{}, 
      "type": "emp", 
      "query": { 
       "match": { 
        "name": "xyz" 
       } 
       } 
      } 
      }, 
      { 
      "bool": 
      { 
       "must": 
       [ 
        { 
        "match" : { "name" : "xyz" } 
        }, 
        { 
        "match" : { "_type" : "emps" } 
        } 
       ], 
       "must_not": [ 
       { 
        "has_child": { 
        "type": "emp", 
        "query": { 
         "exists": 
          { 
           "field": "name" 
          } 
        } 
        } 
       } 
       ] 
      } 
      } 
     ] 
     } 
    } 
} 

回答

1

不幸的是,沒有。

其實,是的。我錯了。 OP對健美的github上發佈his question並取得了以下答案:

這是一個有點古怪,但是這是我會寫:

var inner = bodybuilder() 
    .query('match', 'name', 'xyz') 
    .query('match', '_type', 'emps')  
    .notQuery('has_child', {type: 'emp'}, (q) => { 
     return q.query('exists', 'field', 'name') 
    }) 
    .build() 

bodybuilder() 
    .orQuery('bool', inner.query.bool) 
     .orQuery('has_child', {inner_hits: {}, type: 'emp'}, (q) => { 
     return q.query('match', 'name', 'xyz') 
    }) 
    .build() 

有得 注意: orQuerys的順序在這裏很重要,如果它們被切換,它不起作用 ,這是不理想的。我認爲這是因爲 bool子句是如何被合併的。讓我知道這不是 爲你工作。

+0

請檢查https://github.com/danpaz/bodybuilder/issues/120 – Chirag

+0

對不起,導致你在錯誤的方式。我糾正了我的答案。 –

相關問題