我正在寻找以下伪代码的等价物:
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
挣扎。
有什么想法吗?
提前致谢!
答案 0 :(得分:1)
试试这个:
{
// ...
query: {
bool: {
must: [
{ match: { firstname: 'John' }},
{ match: { gender: 'm' }},
{
bool: {
minimum_should_match: 1,
should: [
{ match: { lastname: 'Doe' }},
{ match: { lastname: 'Wayne' }}
]
}
}
]
}
}
}
答案 1 :(得分:1)
尝试:
{ match: { lastname: /^(Doe|Wayne)$/ }}