Is there a way to reduce the legend length?
Yes, but I would recommend using a different visualization instead. Maybe a data table.
The main way to do this is lossy. You can go to Index Pattern -> Field name -> Formatter and choose the String -> Truncate formatter. This would apply a max length to this field every time you use it in Kibana.