From 0d53785ca1f4115d6f0ad804dd40eec8410ec23f Mon Sep 17 00:00:00 2001 From: Gil Matok Date: Thu, 1 Jun 2023 19:56:02 +0300 Subject: [PATCH] feat: include index name --- .../analysis/DynamicSynonymTokenFilterFactory.java | 6 ++++-- .../plugin/synonym/analysis/RemoteSynonymFile.java | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/bellszhu/elasticsearch/plugin/synonym/analysis/DynamicSynonymTokenFilterFactory.java b/src/main/java/com/bellszhu/elasticsearch/plugin/synonym/analysis/DynamicSynonymTokenFilterFactory.java index 903ebbd..042c24a 100644 --- a/src/main/java/com/bellszhu/elasticsearch/plugin/synonym/analysis/DynamicSynonymTokenFilterFactory.java +++ b/src/main/java/com/bellszhu/elasticsearch/plugin/synonym/analysis/DynamicSynonymTokenFilterFactory.java @@ -47,6 +47,7 @@ public class DynamicSynonymTokenFilterFactory extends }); private volatile ScheduledFuture scheduledFuture; + private final IndexSettings indexSettings; private final String location; private final boolean expand; private final boolean lenient; @@ -65,6 +66,7 @@ public DynamicSynonymTokenFilterFactory( ) throws IOException { super(name, settings); + this.indexSettings = indexSettings; this.location = settings.get("synonyms_path"); if (this.location == null) { throw new IllegalArgumentException( @@ -163,12 +165,12 @@ SynonymFile getSynonymFile(Analyzer analyzer) { SynonymFile synonymFile; if (location.startsWith("http://") || location.startsWith("https://")) { synonymFile = new RemoteSynonymFile( - environment, analyzer, expand, lenient, format, location); + this.indexSettings.getIndex().getName(), environment, analyzer, expand, lenient, format, location); } else { synonymFile = new LocalSynonymFile( environment, analyzer, expand, lenient, format, location); } - if (scheduledFuture == null) { + if (scheduledFuture == null && interval > 0) { scheduledFuture = pool.scheduleAtFixedRate(new Monitor(synonymFile), interval, interval, TimeUnit.SECONDS); } diff --git a/src/main/java/com/bellszhu/elasticsearch/plugin/synonym/analysis/RemoteSynonymFile.java b/src/main/java/com/bellszhu/elasticsearch/plugin/synonym/analysis/RemoteSynonymFile.java index 8e85968..f690b71 100644 --- a/src/main/java/com/bellszhu/elasticsearch/plugin/synonym/analysis/RemoteSynonymFile.java +++ b/src/main/java/com/bellszhu/elasticsearch/plugin/synonym/analysis/RemoteSynonymFile.java @@ -45,6 +45,8 @@ public class RemoteSynonymFile implements SynonymFile { private boolean lenient; + private String indexName; + private Analyzer analyzer; private Environment env; @@ -58,8 +60,9 @@ public class RemoteSynonymFile implements SynonymFile { private String eTags; - RemoteSynonymFile(Environment env, Analyzer analyzer, + RemoteSynonymFile(String indexName, Environment env, Analyzer analyzer, boolean expand, boolean lenient, String format, String location) { + this.indexName = indexName; this.analyzer = analyzer; this.expand = expand; this.lenient = lenient; @@ -134,7 +137,7 @@ public Reader getReader() { .build(); CloseableHttpResponse response = null; BufferedReader br = null; - HttpGet get = new HttpGet(location); + HttpGet get = new HttpGet(location + "?indexName=" + this.indexName); get.setConfig(rc); try { response = executeHttpRequest(get); @@ -191,7 +194,7 @@ public boolean isNeedReloadSynonymMap() { .setConnectionRequestTimeout(10 * 1000) .setConnectTimeout(10 * 1000).setSocketTimeout(15 * 1000) .build(); - HttpHead head = AccessController.doPrivileged((PrivilegedAction) () -> new HttpHead(location)); + HttpHead head = AccessController.doPrivileged((PrivilegedAction) () -> new HttpHead(location + "?indexName=" + this.indexName)); head.setConfig(rc); // 设置请求头