ElasticsearchDSL icon indicating copy to clipboard operation
ElasticsearchDSL copied to clipboard

How to build this query ?

Open khanof89 opened this issue 4 years ago • 0 comments

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();

khanof89 avatar Aug 29 '20 11:08 khanof89