Guhh
Guhh

Reputation: 408

Elastic Search Script Regex Aggregation

I would like to know how can I use regex in a script. Example:

"aggs": {
   "inventary": {
      "sum": {
         "script": "(doc['action'].value == /^request/) ? 1 : 0"
      }
   }
}

So I would like to match every action who matches with request*

It is possible?

Thank you

Upvotes: 1

Views: 560

Answers (1)

Val
Val

Reputation: 217564

Yes, you simply need to use ==~ instead of ==

"aggs": {
   "inventary": {
      "sum": {
         "script": "(doc.action.value ==~ /^request/) ? 1 : 0"
      }
   }
}

Upvotes: 2

Related Questions