Get 255 characters in logstash and store it as a new field

Hi all,
if i want to extract first 255 characters from a field, and also the 255th character is space it should not be splitted , then it should split as 254th character.

Currently i am using the following code for extracting 255 character

ruby{ code => "event.set(('spec1'),event.get('spec')[0..254])" }

How can i check whether the 254th character is space or not.Please help me to how to fix this.

Thanks in advance,
Ranjith

This is a plain Ruby question that people here might find off topic. Perhaps StackOverflow or a Ruby-specific place would be a better fit.

Hi Magnus,

This is ruby code only,but i am trying this logic in logstash.
I need to split the field which contains 1000 of characters into 255 character on each field.

For eg: spec: 1000 character to be be done as
spec1:0-254
spec2:255-509
...

Can you please guide me on this?

Thanks in advance

I have a string data in Logstash that has been parsed as that looks like

{"spec":"Automatic Heavy Duty Safety Slicer Ceraclean© surface finish 13" Grooved Cheese Blade 3-speeds 3-strokes servo assist 8-safety interlocks seamless anodized aluminum construction high carriage 25° incline towards operator 40° gravity feed thumb guard 5.8" W remote sharpener with spring-loaded dial slice thickness 0-0.94" VFD-motor ETL-Sanitation UL-157 gaskets and seals cETLus DGUV safety tested construction high carriage feed thumb guard 5.8" W slice thickness"}

I want the field to look like

"spec1":"Automatic Heavy Duty Safety Slicer Ceraclean© surface finish 13" Grooved Cheese Blade 3-speeds 3-strokes servo assist 8-safety interlocks seamless anodized aluminum construction high carriage 25° incline towards operator 40° gravity feed thumb guard "

"spec2":"5.8" W remote sharpener with spring-loaded dial slice thickness 0-0.94" VFD-motor ETL-Sanitation UL-157 gaskets and seals cETLus DGUV safety tested construction high carriage feed thumb guard 5.8" W slice thickness"

I heard that if I want make loop in Logstash, I have to use ruby filter. Unfortunately I'm not familiar with ruby

Thanks for any help. I really appreciate it.

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