Elasticsearch aggregation to extract pattern and occurrences Elasticsearch aggregation to extract pattern and occurrences elasticsearch elasticsearch

Elasticsearch aggregation to extract pattern and occurrences


Based on the formulation of your request, not sure this will match what you are looking for, but assuming you mean to search based on regex , following should be what you are looking for:

wildcard and regexp queries

Do take note that the behavior will be different whether the field targeted is analyzed or not.Typically if you went with the vanilla setup of Elasticsearch as most people to start, your field will likely be analyzed, you can check your the events mapping in your indices to confirm that.

Based on your example and assuming you have a not_analyzed name field:

GET _search{  "query": {    "regexp": {      "name": "[a-z]{4}"    }  }}GET _search{  "query": {    "regexp": {      "name": "[a-z]{5}[A-Z][a-z]{3}[0-9]{2}"    }  }}

Based on your update, and a quick search (am not that familiar with aggregations), could be something like the following would match your expectations:

GET _search{  "size": 0,  "aggs": {    "regmatch": {      "filters": {        "filters": {          "xxxx": {            "regexp": {              "name": "[a-z]{4}"            }          },          "x{5}Xxxx99": {            "regexp": {              "name": "[a-z]{5}[A-Z][a-z]{3}[0-9]{2}"            }          }        }      }    }  }}

This will give you 3 counts:- total number of events- number of first regex match- number of second regex match