{ "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" } } } } ] } } ] } } }
最佳答案
不幸的是,不。
事实上,是的。我错了。 OP发布his question在 Bodybuilder 的 github 上得到了以下答案:
It's a bit quirky but this is how I'd write it:
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()
Something to watch out for: the order of the orQuerys matters here, it doesn't work if these are switched, which isn't ideal. I think that's because of how the bool clauses are being merged. Let me know is this isn't working for you.
关于elasticsearch - 有没有办法使用 Bodybuilder ElasticSearch 构建带有 has_child 的 "or",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42419058/