Extract value from a field using painless script

Hi there,

i have a use case and i want to try it using painless. so the use case is there is a field containing a valid json and i want to extract just one field from it. basically it's a bit like using grok. the field name is requestPayload and here is the value:


the one field that i want to extract from that value is offer_id.

is it possible if i'm using painless in scripted field to achieve that?

i know i can achieve that by using logstash but there are so many logstash nodes in my cluster. it feels too troublesome. please let me know if you have any idea


you can crerate a runtime field with a script like this

String clientip=grok('Returning %{NUMBER:foobar} ads').extract(params._source.message)?.foobar;

to grok parse and emit a single field

you can use composite runtime field and then you can just do:


Is it possible in kibana v7.17.0?

Pada tanggal Rab, 7 Jun 2023 16.48, Peter Pisljar via Discuss the Elastic Stack <notifications@elastic.discoursemail.com> menulis:

the first option yes, composite runtime fields are however not supported in that kibana version.
you could create multiple fields using the first option to extract more parts.

for my case. since offer_id is not in the beginning of the line, should i make a grok pattern like this?


or i just simply create like this?


and if you don't mind, could you make an example according to my case? i don't really understand what's the point of Returning there? is that just example or it's mandatory to apply in my scripted field? and ads also


i've tried to make the script like this based on this documentation

unfortunately, i got this error in grok part

that's quite surprising because the error is not on pattern or extract part but right on the grok filter

i was tried to make a script based on your example before but the script has return the same error

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