(Reposting this question from slack as we didnt get any feedback there)
Describe the issue:
I’m working on a dashboard visualization, and I need to filter out certain values using a regular expression.
Specifically, I’m trying to match patterns like this:
The end goal is to visualize this filtered data as a line graph on the dashboard. However, I’m struggling with how to implement this in the visState JSON section of the dashboard definition.
I can see some examples of using wildcards in the DQL documentation, but in this case, we need to use regex expression (for more complex cases not achievable through wildcards).
Would anyone be able to share the correct syntax or provide any guidance on how I can apply this regex to display the data properly?
Is this not supported at all and should we raise a feature request for this?
Any help or suggestions would be greatly appreciated!
I’ll give you an example that works for me with opensearch dashboards 2.15:
–I want to get all documents (logs) that contain a text with this pattern:
“12345678912_123456789123”, that is, two groups of numbers separated by an underscore.
It’s true that with DSL searches it’s not possible, but it is possible with DQL queries. You can add a filter in “opensearch Query DSL” like this:
The records are in json format, and there is a field in the record, distinguished_name. It contains a hash in the end of the name that either starts with a digit, or an alphabet character.
alpha case
Regex: TEST-[a-z0-9]+/[a-zA-Z0-9-]+/ind-core-[a-z0-9]±[a-z][a-z0-9]+
Sample string: TEST-vtas251/CON-1/ind-core-677458881-pvplz
digit case
Regex: TEST-[a-z0-9]+/[a-zA-Z0-9-]+/ind-core-[a-z0-9]±[0-9][a-z0-9]+
Sample string: TEST-vtas251/CON-1/ind-core-677458881-8j6sm
Use-case is to add a filter aggregation to distinguish between the two types.
Regular expressions in OpenSearch have some limitations and might not work in all cases, especially if they include non-standard characters like ±. Check if you can simplify the patterns or escape them correctly.
Test the patterns directly in Dev Tools using a regexp query to ensure they match the expected documents:
If you have access to the logs in JSON format, validate that the distinguished_name.keyword field contains values that actually match the described patterns.
Thank you for pointing us in the right direction! Your suggestion provided valuable insights that led us to a potential solution.
As you mentioned, we tried using a DQL query directly, and incorporating the Lucene regex query syntax from OpenSearch documentation proved to be effective.
The key adjustment was correctly escaping the hyphen (-) in the regular expression. Here’s the working regex we used: distinguished_name.keyword: /TEST\-[a-z0-9]+\/[a-zA-Z0-9\-]+\/ind\-core\-[a-z0-9]+\-[a-z][a-z0-9]+/
This resolved the issue for our case. Thanks again for your guidance!