Map ID to predefined name


our application currently logs a locationId, which represents a city.
At some points it is not possible to log the name, since some parts of the application only know the ID.

I'd like to enrich my data witch logstash.

For example, the first thing I would like to do is to add the field "locationName" to it, which contains the Name of the City.
We have a predefined list of Locations, containing around 50 possible IDs/Names.

Something like this seems incredibly inefficient

if "locationId" == 1
   add_field => "New York"
else if "locationId" == 2
   add_field => "Miami"

You get the point.

Another solution I see would be to use ruby to get a value in an array. It could be accessed by using the ID as the position in the array.

Are there any other good ways to do this?

Thanks a lot,

Have a look at the translate filter.

1 Like

That's perfect. Thank you so much