How can I dynamically create elasticsearch indices using logtsash using jdbc?

I have a table in snowflake for which I have a target column. The target column has 20 distinct values and will increase with time. My intention is to use logstash to create separate indices for all the unique values in the target column.

which should behave something like:

targets = """ select distinct target from table """"
for target in targets:
query = "select * from table where target = target" index = 'output_' + target

I understand that's a very pythonic way of explaining but I haven't worked on logstash much.