# \[ES 5.3\] How do I set plugin settings?

**URL:** <https://discuss.elastic.co/t/es-5-3-how-do-i-set-plugin-settings/83274>\
**Category:** Elasticsearch\
**Created:** [April 22, 2017, 11:47am UTC](https://discuss.elastic.co/t/es-5-3-how-do-i-set-plugin-settings/83274 "2017-04-22T11:47:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ddmichael](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ddmichael/32/17212_2.png) [@ddmichael](https://discuss.elastic.co/u/ddmichael)\
**Post date:** [April 22, 2017, 11:47am UTC](https://discuss.elastic.co/t/es-5-3-how-do-i-set-plugin-settings/83274/1 "2017-04-22T11:47:30Z")

</div>

I am writing an integration test for elasticsearch 5.3. (note: placing and overriding the refresh interval in the node settings was working on elasticsearch 1.7)

```
public class ProtectedWordsIndexTests extends ESIntegTestCase {
  private final WordDelimiterActionListener wordsListener = 
  WordDelimiterActionListener.getInstance();
  private final static String INDEX_NAME = "protected_words";
  private final static String TYPE_NAME = "word";
  private final static String FILTER_NAME = "my_word_delimiter";

  @Override
  protected Collection<Class<? extends Plugin>> nodePlugins() {
     return Collections.singleton(WordDelimiterPlugin.class);
  }

  @Override
  protected Settings nodeSettings(int nodeOrdinal) {
    return builder()
       .put("plugin.types", TYPE_NAME)
       .put("plugin.dynamic_word_delimiter.refresh_interval", "500ms")
       .put(super.nodeSettings(nodeOrdinal))
       .build();
  }

  public void testAddWordToIndex() throws Exception {
     Settings indexSettings = builder()
       .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
       .put("index.analysis.filter.my_word_delimiter.type", "dynamic_word_delimiter")
       .build();
     TokenFilterFactory filterFactory = filterFactory(indexSettings, FILTER_NAME);

     createIndex(INDEX_NAME);
     ensureGreen();
     client().prepareIndex(INDEX_NAME, TYPE_NAME, "1")
        .setSource("word", "1tb")
        .execute();

     Thread.sleep(TimeValue.timeValueSeconds(1).getMillis());

     Set<String> protectedWords = wordsListener.getProtectedWords();
     assertTrue(protectedWords.size() == 1);
  }
}

```

When I am running testAddWordToIndex() I am getting the following error:

> "java.lang.IllegalArgumentException: unknown setting [plugin.dynamic\_word\_delimiter.refresh\_interval] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"  
> If I remove the following part and increase the refresh interval to be more than the default, the test passes. So I just can't override this.

.put("plugin.dynamic\_word\_delimiter.refresh\_interval", "500ms")  
The default refresh interval is declared here:

```
public class WordDelimiterRunnable extends AbstractRunnable {
   public static final TimeValue REFRESH_INTERVAL = TimeValue.timeValueSeconds(20);
   public static final String INDEX_NAME = "protected_words";
   public static final String INDEX_TYPE = "word";
   public static final int RESULTS_SIZE = 10000;

   private volatile boolean running;
   private final Client client;
   private final String index;
   private final long interval;
   private final String type;

   public WordDelimiterRunnable(Client client, Settings settings) {
     this.client = client;
     this.index = settings.get("plugin.dynamic_word_delimiter.protected_words_index", INDEX_NAME);
     this.type = settings.get("plugin.dynamic_word_delimiter.protected_words_type", INDEX_TYPE);
     this.interval = settings.getAsTime("plugin.dynamic_word_delimiter.refresh_interval", REFRESH_INTERVAL).getMillis();
   }
   // more code here
}

```

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [April 28, 2017, 2:01pm UTC](https://discuss.elastic.co/t/es-5-3-how-do-i-set-plugin-settings/83274/2 "2017-04-28T14:01:50Z")

</div>

I'm not positive this is the solution, but I think you need to also override `transportClientPlugins`:

```auto
@Override
protected final Collection<Class<? extends Plugin>> transportClientPlugins() {
     return nodePlugins();
}

```

---

<div class="post-metadata">

**Author:** ![ddmichael](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ddmichael/32/17212_2.png) [@ddmichael](https://discuss.elastic.co/u/ddmichael)\
**Post date:** [April 28, 2017, 2:17pm UTC](https://discuss.elastic.co/t/es-5-3-how-do-i-set-plugin-settings/83274/3 "2017-04-28T14:17:50Z")

</div>

Thanks. I finally found the missing link. I had to prefix the settings' strings with "node.attr". Hence,  
"node.attr.plugin.dynamic\_word\_delimiter.protected\_words\_index" etc..

[https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking\_50\_settings\_changes.html#\_node\_attribute\_settings](https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking_50_settings_changes.html#_node_attribute_settings)

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [April 28, 2017, 7:46pm UTC](https://discuss.elastic.co/t/es-5-3-how-do-i-set-plugin-settings/83274/4 "2017-04-28T19:46:42Z")

</div>

`node.attr.*` is for something completely different. In this case you will be able to set your settings with that prefix, but reading them as you are in your plugin will not work.

Each plugin needs to register the settings it expects to read. This is done by overriding the `getSettings()` method on the `Plugin` class. That method returns a collection of `Setting` objects.

For example, for your `plugin.dynamic_word_delimiter.refresh_interval` setting, you can create a `Setting` object with:

```auto
static final Setting REFRESH_INTERVAL_SETTING = Setting.timeValue("plugin.dynamic_word_delimiter.refresh_interval", TimeValue.timeValueSeconds(10), Setting.Property.NodeScope);

```

Then when reading your setting in the `WordDelimiterRunnable` constructor, use:

```auto
this.interval = REFRESH_INTERVAL_SETTING.get(settings);

```

One last thing: if you plan to release this plugin, I would suggest using a more descriptive prefix than "plugin", since there may be many plugins installed.

---

<div class="post-metadata">

**Author:** ![ddmichael](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ddmichael/32/17212_2.png) [@ddmichael](https://discuss.elastic.co/u/ddmichael)\
**Post date:** [May 3, 2017, 9:07am UTC](https://discuss.elastic.co/t/es-5-3-how-do-i-set-plugin-settings/83274/5 "2017-05-03T09:07:48Z")

</div>

Thanks for the enlightening answer! The thing is it works though. That is:

1. `WordDelimiterRunnable` correctly reads and sets the settings (using the node.attr.\* prefix) which I defined inside the class.
2. Overriding the settings in elasticsearch.yml (using the node.attr.\* prefix) indeed does what it's supposed to do.

I know that the above both work as I am setting the interval to an expected and measurable value, like 5 seconds and 30 seconds.

@rjernst any idea why it's working and whether it's really necessary to override `Plugin's` `getSettings`?

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [May 3, 2017, 8:33pm UTC](https://discuss.elastic.co/t/es-5-3-how-do-i-set-plugin-settings/83274/6 "2017-05-03T20:33:04Z")

</div>

When you are setting `node.attr.plugin.dynamic_word_delimiter.protected_words_index`, do you then read that _exact_ setting name, or just `plugin.dynamic_word_delimiter.protected_words_index`? The code you had above did the latter, which should not work. But if you did the following, it would probably work (but still be wrong, these attrs are meant for allocator attributes, ie rack awareness):

`settings.get("node.attr.plugin.dynamic_word_delimiter.protected_words_index", INDEX_NAME);`

Overriding `getSettings()` is necessary; it is what that method was designed for.

---

<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:** [May 31, 2017, 8:46pm UTC](https://discuss.elastic.co/t/es-5-3-how-do-i-set-plugin-settings/83274/7 "2017-05-31T20:46:00Z")

</div>

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