【发布时间】:2017-09-19 02:37:20
【问题描述】:
我正在为 elasticsearch 5.3 编写集成测试。
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);
}
}
当我运行 testAddWordToIndex() 时,我收到以下错误:
"java.lang.IllegalArgumentException: 未知设置 [plugin.dynamic_word_delimiter.refresh_interval] 请检查任何 已安装所需的插件,或检查重大更改 删除设置的文档”
如果我删除以下部分并将刷新间隔增加到默认值以上,则测试通过。所以我无法覆盖它。
.put("plugin.dynamic_word_delimiter.refresh_interval", "500ms")
这里声明了默认的刷新间隔:
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
}
【问题讨论】:
-
我没试过这个,所以评论,但也许它与 put() 的顺序有关?我会尝试做`return builder().put(super.nodeSettings(nodeOrdinal)).put("plugin.types", TYPE_NAME).put("plugin.dynamic_word_delimiter.refresh_interval", "500ms").build(); ` 如果你还没有
-
感谢您的评论。想了想,试过了,还是不行。
-
.put("plugin.types", TYPE_NAME)通常取插件的类名。从异常中它说插件未加载。如果你有插件的类名,你可以试试 -
也试过了,没有任何变化。
标签: java elasticsearch elasticsearch-plugin