diff --git a/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java b/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java index d4bc3d3adf2..66d21d04cb6 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java @@ -34,7 +34,6 @@ import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.routing.ShardsIterator; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.analysis.*; @@ -213,7 +212,7 @@ public class TransportAnalyzeAction extends TransportSingleCustomOperationAction closeAnalyzer = true; } else if (analyzer == null) { if (indexService == null) { - analyzer = Lucene.STANDARD_ANALYZER; + analyzer = indicesAnalysisService.analyzer("standard"); } else { analyzer = indexService.analysisService().defaultIndexAnalyzer(); } diff --git a/src/test/java/org/elasticsearch/indices/analyze/AnalyzeActionTests.java b/src/test/java/org/elasticsearch/indices/analyze/AnalyzeActionTests.java index cdd15cf2e8f..48dfeded927 100644 --- a/src/test/java/org/elasticsearch/indices/analyze/AnalyzeActionTests.java +++ b/src/test/java/org/elasticsearch/indices/analyze/AnalyzeActionTests.java @@ -31,6 +31,8 @@ import java.io.IOException; import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; /** * @@ -172,4 +174,23 @@ public class AnalyzeActionTests extends ElasticsearchIntegrationTest { assertThat(token.getEndOffset(), equalTo(14)); } } + + @Test // issue #5974 + public void testThatStandardAndDefaultAnalyzersAreSame() throws Exception { + AnalyzeResponse response = client().admin().indices().prepareAnalyze("this is a test").setAnalyzer("standard").get(); + assertTokens(response, "this", "is", "a", "test"); + + response = client().admin().indices().prepareAnalyze("this is a test").setAnalyzer("default").get(); + assertTokens(response, "this", "is", "a", "test"); + + response = client().admin().indices().prepareAnalyze("this is a test").get(); + assertTokens(response, "this", "is", "a", "test"); + } + + private void assertTokens(AnalyzeResponse response, String ... tokens) { + assertThat(response.getTokens(), hasSize(tokens.length)); + for (int i = 0; i < tokens.length; i++) { + assertThat(response.getTokens().get(i).getTerm(), is(tokens[i])); + } + } }