I have this SQL:
select *
from users
where company_id = null
or company_id = 123
How can I write a similar query in Elasticsearch? I want the query to return all candidates who have a company_id
that is nil
or who have a company_id
that matches the current user.
I have tried this with should
:
query: {
bool: {
should: [
{
bool: {
must_not: {
exists: {
field: "company_id"
}
}
}
},
{
term: {
company_id: 123
}
}
]
}
}
This returns users whose company_id
is nil
.
I've tried this with regex also but it returns users who have a company_id
.
query: {
bool: {
should: [
{
regexp: {
comapny_id: ".+"
}
},
{
term: {
company_id: {
value: 123
}
}
}
]
}
}
Thank you.