ElasticsearchDSL
ElasticsearchDSL copied to clipboard
How to build this query ?
I really wanted to sort this out on my own but couldn't get it working in last 2 hours so asking for help, I need to create the following query:
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"match": {
"description": "head of marketing"
}
},
{
"match": {
"has_email": 1
}
}
]
}
},
{
"bool": {
"must": [
{
"match": {
"description": "cmo"
}
},
{
"match": {
"has_email": 1
}
}
]
}
}
]
}
}
}
this is what I have done, but its not getting the required result:
$search = new Search();
$descriptionMatch = new MatchQuery('description', 'head of marketing');
$emailMatch = new MatchQuery('has_email', 1);
$search->addQuery($descriptionMatch, BoolQuery::MUST);
$search->addQuery($emailMatch, BoolQuery::MUST);
return $search->toArray();