Dictionary in Kibana for translation


(scch) #1

How to create a dictionary or refer an external csv file to translate and generate scripted fields using painless.

i am aware of similar function in Logstash, grok filter, but need to create scripted field using painless.

thank you...


(Tim Roes) #2

Hey,

sorry for the very late response.

For security and scaleability reasons, you are not able to access local files or such in Painless scripts, meaning you would need to hardcode that dictionary in your scripted field like:

def dict = [ 'key1': 'some-value', 'another-key': 'another-value' ];
return dict[doc['your_key_field'].value]

If your field can have sparse data or your dictionary might not cover all possible values, you might want to add some null checks in the above code.

Cheers,
Tim


(scch) #3

Hi Tim,
This helps and convenient otherwise i hard coded if else construct...

also, can you please point me to some detailed documentation on painless scripting(functions,methods and usage). i am new to to ELK especially for painless scripting and struggling to code even sorting and counting snips.

I tried translating java script snips but failed.

currently looks like it is very painful..
Can we start new group on painless scripting....?

Thank you....


(Tim Roes) #4

Hi,

the official documentation can be found on elastic.co. There is also an API reference available.

Regarding the group. Since Painless is an Elasticsearch build-in feature, I think the best place would be the Elasticsearch subforum to ask questions regarding Painless at the moment.

@warkolm Do you think we should create a custom subforum for painless? That way we would have a centralized place to ask and also a better place to look for already existing answers then we have currently?

Cheers,
Tim


(system) #5

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