Skip to content

Commit 66c7bfa

Browse files
author
Christoph Büscher
committed
Adding ReloadAnalyzerAction
1 parent 3f02fa5 commit 66c7bfa

File tree

13 files changed

+449
-19
lines changed

13 files changed

+449
-19
lines changed

modules/analysis-common/src/test/java/org/elasticsearch/analysis/common/SynonymAnalyzerIT.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.lucene.util.LuceneTestCase.AwaitsFix;
2323
import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse;
2424
import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse.AnalyzeToken;
25+
import org.elasticsearch.action.admin.indices.reloadanalyzer.ReloadAnalyzersResponse;
2526
import org.elasticsearch.action.search.SearchResponse;
2627
import org.elasticsearch.common.settings.Settings;
2728
import org.elasticsearch.index.query.QueryBuilders;
@@ -82,8 +83,8 @@ public void testSynonymsUpdateable() throws FileNotFoundException, IOException {
8283
}
8384
assertTrue(Files.exists(synonymsFile));
8485
assertAcked(client().admin().indices().prepareCreate("test").setSettings(Settings.builder()
85-
.put("index.number_of_shards", 1)
86-
.put("index.number_of_replicas", 0)
86+
.put("index.number_of_shards", cluster().numDataNodes() * 2)
87+
.put("index.number_of_replicas", 1)
8788
.put("analysis.analyzer.my_synonym_analyzer.tokenizer", "standard")
8889
.put("analysis.analyzer.my_synonym_analyzer.filter", "my_synonym_filter")
8990
.put("analysis.filter.my_synonym_filter.type", "synonym")
@@ -108,8 +109,9 @@ public void testSynonymsUpdateable() throws FileNotFoundException, IOException {
108109
new OutputStreamWriter(Files.newOutputStream(synonymsFile, StandardOpenOption.WRITE), StandardCharsets.UTF_8))) {
109110
out.println("foo, baz, buzz");
110111
}
111-
// TODO don't use refresh here but something more specific
112-
assertNoFailures(client().admin().indices().prepareRefresh("test").execute().actionGet());
112+
ReloadAnalyzersResponse reloadResponse = client().admin().indices().prepareReloadAnalyzers("test").execute().actionGet();
113+
assertNoFailures(reloadResponse);
114+
assertEquals(cluster().numDataNodes(), reloadResponse.getSuccessfulShards());
113115

114116
analyzeResponse = client().admin().indices().prepareAnalyze("test", "foo").setAnalyzer("my_synonym_analyzer").get();
115117
assertEquals(3, analyzeResponse.getTokens().size());

modules/analysis-common/src/test/java/org/elasticsearch/analysis/common/SynonymAnalyzerTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void testSynonymsUpdateable() throws FileNotFoundException, IOException {
6767
}
6868

6969
assertAcked(client().admin().indices().prepareCreate("test").setSettings(Settings.builder()
70-
.put("index.number_of_shards", 1)
70+
.put("index.number_of_shards", 5)
7171
.put("index.number_of_replicas", 0)
7272
.put("analysis.analyzer.my_synonym_analyzer.tokenizer", "standard")
7373
.putList("analysis.analyzer.my_synonym_analyzer.filter", "lowercase", "my_synonym_filter")
@@ -93,8 +93,7 @@ public void testSynonymsUpdateable() throws FileNotFoundException, IOException {
9393
new OutputStreamWriter(Files.newOutputStream(synonymsFile, StandardOpenOption.WRITE), StandardCharsets.UTF_8))) {
9494
out.println("foo, baz, buzz");
9595
}
96-
// TODO don't use refresh here but something more specific
97-
assertNoFailures(client().admin().indices().prepareRefresh("test").execute().actionGet());
96+
assertNoFailures(client().admin().indices().prepareReloadAnalyzers("test").execute().actionGet());
9897

9998
analyzeResponse = client().admin().indices().prepareAnalyze("test", "Foo").setAnalyzer("my_synonym_analyzer").get();
10099
assertEquals(3, analyzeResponse.getTokens().size());

server/src/main/java/org/elasticsearch/action/ActionModule.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@
125125
import org.elasticsearch.action.admin.indices.recovery.TransportRecoveryAction;
126126
import org.elasticsearch.action.admin.indices.refresh.RefreshAction;
127127
import org.elasticsearch.action.admin.indices.refresh.TransportRefreshAction;
128+
import org.elasticsearch.action.admin.indices.reloadanalyzer.ReloadAnalyzerAction;
129+
import org.elasticsearch.action.admin.indices.reloadanalyzer.TransportReloadAnalyzersAction;
128130
import org.elasticsearch.action.admin.indices.rollover.RolloverAction;
129131
import org.elasticsearch.action.admin.indices.rollover.TransportRolloverAction;
130132
import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsAction;
@@ -509,6 +511,7 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
509511
actions.register(ClearScrollAction.INSTANCE, TransportClearScrollAction.class);
510512
actions.register(RecoveryAction.INSTANCE, TransportRecoveryAction.class);
511513
actions.register(NodesReloadSecureSettingsAction.INSTANCE, TransportNodesReloadSecureSettingsAction.class);
514+
actions.register(ReloadAnalyzerAction.INSTANCE, TransportReloadAnalyzersAction.class);
512515

513516
//Indexed scripts
514517
actions.register(PutStoredScriptAction.INSTANCE, TransportPutStoredScriptAction.class);

server/src/main/java/org/elasticsearch/action/admin/indices/refresh/TransportShardRefreshAction.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ protected void shardOperationOnPrimary(BasicReplicationRequest shardRequest, Ind
5858
ActionListener<PrimaryResult<BasicReplicationRequest, ReplicationResponse>> listener) {
5959
ActionListener.completeWith(listener, () -> {
6060
primary.refresh("api");
61-
try {
62-
primary.mapperService().reloadSearchAnalyzers(indicesService.getAnalysis());
63-
} catch (Exception ex) {
64-
logger.error(ex.getLocalizedMessage(), ex);
65-
return new PrimaryResult(null, null, ex);
66-
}
6761
logger.trace("{} refresh request executed on primary", primary.shardId());
6862
return new PrimaryResult<>(shardRequest, new ReplicationResponse());
6963
});
@@ -72,12 +66,6 @@ protected void shardOperationOnPrimary(BasicReplicationRequest shardRequest, Ind
7266
@Override
7367
protected ReplicaResult shardOperationOnReplica(BasicReplicationRequest request, IndexShard replica) {
7468
replica.refresh("api");
75-
try {
76-
replica.mapperService().reloadSearchAnalyzers(indicesService.getAnalysis());
77-
} catch (Exception ex) {
78-
logger.error(ex.getLocalizedMessage(), ex);
79-
return new ReplicaResult(ex);
80-
}
8169
logger.trace("{} refresh request executed on replica", replica.shardId());
8270
return new ReplicaResult();
8371
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.action.admin.indices.reloadanalyzer;
21+
22+
import org.elasticsearch.action.Action;
23+
24+
public class ReloadAnalyzerAction extends Action<ReloadAnalyzersResponse> {
25+
26+
public static final ReloadAnalyzerAction INSTANCE = new ReloadAnalyzerAction();
27+
public static final String NAME = "indices:admin/reload_analyzers";
28+
29+
private ReloadAnalyzerAction() {
30+
super(NAME);
31+
}
32+
33+
@Override
34+
public ReloadAnalyzersResponse newResponse() {
35+
return new ReloadAnalyzersResponse();
36+
}
37+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.action.admin.indices.reloadanalyzer;
21+
22+
import org.elasticsearch.action.support.broadcast.BroadcastOperationRequestBuilder;
23+
import org.elasticsearch.client.ElasticsearchClient;
24+
25+
/**
26+
* Builder for reloading of analyzers
27+
*/
28+
public class ReloadAnalyzerRequestBuilder
29+
extends BroadcastOperationRequestBuilder<ReloadAnalyzersRequest, ReloadAnalyzersResponse, ReloadAnalyzerRequestBuilder> {
30+
31+
public ReloadAnalyzerRequestBuilder(ElasticsearchClient client, ReloadAnalyzerAction action, String... indices) {
32+
super(client, action, new ReloadAnalyzersRequest(indices));
33+
}
34+
35+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.action.admin.indices.reloadanalyzer;
21+
22+
import org.elasticsearch.action.ActionRequestValidationException;
23+
import org.elasticsearch.action.support.broadcast.BroadcastRequest;
24+
import org.elasticsearch.common.io.stream.StreamInput;
25+
import org.elasticsearch.common.io.stream.StreamOutput;
26+
import org.elasticsearch.common.settings.Settings;
27+
28+
import java.io.IOException;
29+
import java.util.Arrays;
30+
import java.util.Objects;
31+
32+
/**
33+
* Request for reloading index search analyzers
34+
*/
35+
public class ReloadAnalyzersRequest extends BroadcastRequest<ReloadAnalyzersRequest> {
36+
37+
public ReloadAnalyzersRequest() {
38+
}
39+
40+
/**
41+
* Constructs a new request for reloading index search analyzers for one or more indices
42+
*/
43+
public ReloadAnalyzersRequest(String... indices) {
44+
this.indices = indices;
45+
}
46+
47+
/**
48+
* Constructs a new request for reloading index search analyzers for one or more indices
49+
*/
50+
public ReloadAnalyzersRequest(Settings settings, String... indices) {
51+
this.indices = indices;
52+
}
53+
54+
@Override
55+
public ActionRequestValidationException validate() {
56+
ActionRequestValidationException validationException = null;
57+
return validationException;
58+
}
59+
60+
@Override
61+
public String[] indices() {
62+
return indices;
63+
}
64+
65+
@Override
66+
public void readFrom(StreamInput in) throws IOException {
67+
super.readFrom(in);
68+
}
69+
70+
@Override
71+
public void writeTo(StreamOutput out) throws IOException {
72+
super.writeTo(out);
73+
}
74+
75+
@Override
76+
public String toString() {
77+
return "indices : " + Arrays.toString(indices);
78+
}
79+
80+
@Override
81+
public boolean equals(Object o) {
82+
if (this == o) {
83+
return true;
84+
}
85+
if (o == null || getClass() != o.getClass()) {
86+
return false;
87+
}
88+
ReloadAnalyzersRequest that = (ReloadAnalyzersRequest) o;
89+
return Objects.equals(indicesOptions(), that.indicesOptions())
90+
&& Arrays.equals(indices, that.indices);
91+
}
92+
93+
@Override
94+
public int hashCode() {
95+
return Objects.hash(indicesOptions(), Arrays.hashCode(indices));
96+
}
97+
98+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.elasticsearch.action.admin.indices.reloadanalyzer;
20+
21+
import org.elasticsearch.action.support.DefaultShardOperationFailedException;
22+
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
23+
24+
import java.util.List;
25+
26+
/**
27+
* The response object that will be returned when reloading analyzers
28+
*/
29+
public class ReloadAnalyzersResponse extends BroadcastResponse {
30+
31+
public ReloadAnalyzersResponse() {
32+
}
33+
34+
public ReloadAnalyzersResponse(int totalShards, int successfulShards, int failedShards,
35+
List<DefaultShardOperationFailedException> shardFailures) {
36+
super(totalShards, successfulShards, failedShards, shardFailures);
37+
}
38+
}

0 commit comments

Comments
 (0)