How to write dsl query using regex

HI,

I want to write query to find a string of the following kind in the message.
using regex

it's a 16 digit number enclosed in the brackets with out any special characters

like the below : [QV07HG91005554LL]

Please help me solve it.

You can use https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html

But it also depends on the analyzer you are using.

hi @dadoonet,

i need to know the logic or regex for such kind of 16 lettered string enclosed in the square brackest?

Not sure I understood the question.

i need a regex to search this kind of string " [QV07HG91005554LL]" in my message field.

So use the regex query.

that kind of strings are unique in our message and we want to caputure them
so i need regex for a alphanumeric string of length 16 enclosed in a bracket

so that my query can capture any string which matches that regex:

Targeted strings looks like the following :
[QV07HG91005554LL]
[CD01GH9267684HW]
[QVO2TD94981245FZ]

I'm not a regex expert. And it's outside of the scope of elasticsearch.
So you need to find the right regex then use it in the regex query.

Note that it won't match if you are still using a standard analyzer. I believe you would need a keyword analyzer instead.
BTW may be this is something you should extract at index time in a specific field? But as I don't know the use case and the json documents, I might be wrong.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.