# Passing parameters to Java filter plugin during runtime

**URL:** <https://discuss.elastic.co/t/passing-parameters-to-java-filter-plugin-during-runtime/258062>\
**Category:** Logstash\
**Created:** [December 8, 2020, 11:43pm UTC](https://discuss.elastic.co/t/passing-parameters-to-java-filter-plugin-during-runtime/258062 "2020-12-08T23:43:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lakechat](https://avatars.discourse-cdn.com/v4/letter/l/c2a13f/32.png) [@lakechat](https://discuss.elastic.co/u/lakechat)\
**Post date:** [December 8, 2020, 11:43pm UTC](https://discuss.elastic.co/t/passing-parameters-to-java-filter-plugin-during-runtime/258062/1 "2020-12-08T23:43:37Z")

</div>

The Java filter plugin example ([https://www.elastic.co/guide/en/logstash/current/java-filter-plugin.html](https://www.elastic.co/guide/en/logstash/current/java-filter-plugin.html)) was called without any inputs because everything is fixed during compilation time. This makes the plugin less generic. Is it possible to pass some user inputs to the Java plugin during runtime? I could not find any examples or documentations.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [December 9, 2020, 12:12am UTC](https://discuss.elastic.co/t/passing-parameters-to-java-filter-plugin-during-runtime/258062/2 "2020-12-09T00:12:41Z")

</div>

If you asking whether a filter can have options then the answer is yes. The example you linked to [includes an option](https://www.elastic.co/guide/en/logstash/current/java-filter-plugin.html#_plugin_settings_3).

---

<div class="post-metadata">

**Author:** ![lakechat](https://avatars.discourse-cdn.com/v4/letter/l/c2a13f/32.png) [@lakechat](https://discuss.elastic.co/u/lakechat)\
**Post date:** [December 9, 2020, 12:40am UTC](https://discuss.elastic.co/t/passing-parameters-to-java-filter-plugin-during-runtime/258062/3 "2020-12-09T00:40:39Z")

</div>

Hi,  
Would you please be more specific? I could not find the "options" in this example. Thanks.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [December 9, 2020, 1:55am UTC](https://discuss.elastic.co/t/passing-parameters-to-java-filter-plugin-during-runtime/258062/4 "2020-12-09T01:55:02Z")

</div>

Just to make sure we are using the same terminology. When I speak of options I am talking about things like the [allow\_duplicate\_values](https://www.elastic.co/guide/en/logstash/current/plugins-filters-kv.html#plugins-filters-kv-options) option of a kv filter, or the source and target options of a json filter.

The java plugin documentation [refers to these as settings](https://www.elastic.co/guide/en/logstash/current/java-filter-plugin.html#_constructor_and_initialization_3), which is inconsistent with most logstash documentation.

The [PluginConfigSpec code](https://github.com/elastic/logstash/blob/master/logstash-core/src/main/java/co/elastic/logstash/api/PluginConfigSpec.java) allows the filter writer to define options using just the name, or the name and default value (the example in the documentation), all the way up to the name, the type, the defaultValue, whether the option is deprecated, whether it is required, and what its children are. And no, I have no idea what children means in this context.

I assume if you are writing a Java plugin you can figure out what PluginConfigSpec java code does, since your knowledge of Java is almost certainly far better than mine 😃

---

<div class="post-metadata">

**Author:** ![lakechat](https://avatars.discourse-cdn.com/v4/letter/l/c2a13f/32.png) [@lakechat](https://discuss.elastic.co/u/lakechat)\
**Post date:** [December 9, 2020, 10:36pm UTC](https://discuss.elastic.co/t/passing-parameters-to-java-filter-plugin-during-runtime/258062/5 "2020-12-09T22:36:40Z")

</div>

Hi,

Here is my use case.

I am writing a plugin to calculate time duration. In my logs, there are fields called "timetaken" or "sqltime" or "acltime", and many other names. But they all in the form of "hour:minute:second:millisecond". With the information provided by the Java plugin example, I have to hardcode the field name (e.getField("timetaken")) in order to get the value. This limits the plugin only works for logs with field name as "timetaken". I want to be able to use e.getField(input\_parameter), where this input\_parameter (can be "timetaken", "sqltime", "acltime",...) is passed in from Logstash pipeline. This will make plugin generic. In other words, can I invoke the plugin just like making an api call with parameters? I could not find any examples or documents on this. Logstash built-in Java plugins are not implemented with these APIs.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [December 9, 2020, 10:53pm UTC](https://discuss.elastic.co/t/passing-parameters-to-java-filter-plugin-during-runtime/258062/6 "2020-12-09T22:53:34Z")

</div>

Read through the documentation and focus on how sourceField is used. The example plugin only has one option, but you could have more than one.

The [helper code](https://github.com/elastic/logstash/blob/master/logstash-core/src/main/java/co/elastic/logstash/api/PluginHelper.java) may help you see how to configuration multiple options.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 6, 2021, 10:54pm UTC](https://discuss.elastic.co/t/passing-parameters-to-java-filter-plugin-during-runtime/258062/7 "2021-01-06T22:54:04Z")

</div>

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