geekscrap
geekscrap

Reputation: 1045

Add field/string length to logstash event

I'm trying to add a string length field to an index. Ideally, I'd like to use the kibana script feature as I can 'add' this field later but I keep getting a null_pointer_exception with the following code... I'm trying to sort in a visualization based on the fields length.

doc['field'].value ? doc['field'].length() : 0

Is this correct?

I thought it was because my field isn't always set (sparse data), but I added the ?:0 to combat that (which didn't work)

Any ideas?

Upvotes: 0

Views: 789

Answers (1)

Imma
Imma

Reputation: 499

You can define an scripted field in Kibana, of type int, language painless, and try this:

return (doc['field'].value != null? doc['field'].value.length(): 0);

Upvotes: 1

Related Questions