0

I have a search that in some situations needs to be searched by a regex query

GET my-index/_search
{
  "query": {
    "regexp":{  
      "name":".*something.*"
    }  
  }

}

And sometimes needs to be filtered, like so:

GET /my-index/_search
{  
  "query":{  
      "bool":{  
      "filter":[  
           {  
              "term":{  
                 "createdByEmail.keyword":"[email protected]"
              }
           }
      ]
  }
}  

I want to combine these 2 so that it will only show me resolts where the name matches the regex AND the createdByEmail matches the email address I'm sending in.

1 Answer 1

5

You can add first query inside must clause of second as below:

{
  "query": {
    "bool": {
      "must": [
        {
          "regexp": {
            "name": ".*something.*"
          }
        }
      ],
      "filter": [
        {
          "term": {
            "createdByEmail.keyword": "[email protected]"
          }
        }
      ]
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.