Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have multiple regex based on or condition in elasticsearch?

I want to get all 000ANT and 0BBNTA from id, is there something similar to terms which works with regexp or is there any other way? Otherwise I will have to query elasticsearch for each item say 000ANT and 0BBNTA. Please help.

Below is something that I am trying out for 1 i.e., 000ANT but I also want to have a or condition so regex can also match 0BBNTA.

GET dc/ma/_search
{
   "fields": [
       "host"
    ],
   "filter": {
      "bool": {
         "must": [
            {
               "regexp": {
                  "_uid": {
                     "value": ".*000ANT.*"
                  }
               }
            }
         ]
      }
   }
}
like image 683
AabinGunz Avatar asked Oct 19 '25 09:10

AabinGunz


1 Answers

Use a should instead of a must:

{
   "fields": [
       "host"
    ],
   "filter": {
      "bool": {
         "should": [
            {
               "regexp": {
                  "_uid": {
                     "value": ".*000ANT.*"
                  }
               }
            },
            {
               "regexp": {
                  "_uid": {
                     "value": ".*0BBNTA.*"
                  }
               }
            }
         ]
      }
   }
}
like image 94
Andrei Stefan Avatar answered Oct 22 '25 04:10

Andrei Stefan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!