How to use regex in kibana painless script?


(Mouli) #1

given query is working in kibana query DSL
{
"query": {
"regexp": {
"path": "/hma/v1.0/.*"
}
}
}
can you please help me How to write painless script for above query?


#2

What additional value are you hoping to get from a painless script vs. your query? Without knowing that then I'd stick with your query as is.

Here are painless examples: https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-examples.html
RegEx is currently disabled by default for painless scripting.


(Mouli) #4

Thanks for quick reply stilts.
I want to use same query to create a new field by using kibana painless script however I am not able to do that.
My painless script is:
if(doc["path"].value == "/hma/v1.0/customer/.*")
{
return customer
}

== is working for only exactly matched records not for regex.
What operator should I use for regex?
I have enabled regex in my elasticsearch.yml file.


(Christian Dahlqvist) #5

I am not sure I understand why you are trying to do what you do. A bit of background to the problem you are trying to solve would be useful.

Using scripted fields with regular expressions is likely to be quite slow and not scale well. If this data is something you want to do analysis on on a regular basis the best way is to extract it and put it into a separate field before you index the data into Elasticsearch.


(Mouli) #6

Hi Christian thanks for your quick response.
I don't understand clearly can you please explain with query.

"the best way is to extract it and put it into a separate field before you index the data into Elasticsearch."


(Christian Dahlqvist) #7

Which parts of the string is it you want to filter/search/aggregate on? What is it you want to do with this field/data? What does the different parts of the path represent?


(system) closed #8

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