diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequest.java index 3bf08d56825..a5189c12aec 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeRequest.java @@ -42,8 +42,6 @@ public class AnalyzeRequest extends SingleCustomOperationRequest { private String analyzer; - private String type; - private String field; AnalyzeRequest() { @@ -83,15 +81,6 @@ public class AnalyzeRequest extends SingleCustomOperationRequest { return this.analyzer; } - public AnalyzeRequest type(String type) { - this.type = type; - return this; - } - - public String type() { - return this.type; - } - public AnalyzeRequest field(String field) { this.field = field; return this; @@ -128,9 +117,6 @@ public class AnalyzeRequest extends SingleCustomOperationRequest { if (in.readBoolean()) { analyzer = in.readUTF(); } - if (in.readBoolean()) { - type = in.readUTF(); - } if (in.readBoolean()) { field = in.readUTF(); } @@ -141,12 +127,11 @@ public class AnalyzeRequest extends SingleCustomOperationRequest { out.writeUTF(index); out.writeUTF(text); writeOption(out, analyzer); - writeOption(out, type); writeOption(out, field); } private void writeOption(StreamOutput out, String value) throws IOException { - if (value==null) { + if (value == null) { out.writeBoolean(false); } else { out.writeBoolean(true); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java index 97fea967ada..7b001f599b0 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java @@ -36,7 +36,7 @@ import org.elasticsearch.common.collect.Lists; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.FastStringReader; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.mapper.DocumentMapper; +import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.service.IndexService; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.threadpool.ThreadPool; @@ -86,19 +86,20 @@ public class TransportAnalyzeAction extends TransportSingleCustomOperationAction @Override protected AnalyzeResponse shardOperation(AnalyzeRequest request, int shardId) throws ElasticSearchException { IndexService indexService = indicesService.indexServiceSafe(request.index()); Analyzer analyzer = null; - String field = "contents"; - String dtype = null; - if (request.field()!=null) field = request.field(); - if (request.type()!=null) dtype = request.type(); - if (request.field()!=null || request.type()!=null) { - final DocumentMapper mapper = indexService.mapperService().documentMapper(dtype); - if (mapper!=null) { - analyzer = mapper.mappers().indexAnalyzer(); + String field = null; + if (request.field() != null) { + FieldMapper fieldMapper = indexService.mapperService().smartNameFieldMapper(request.field()); + if (fieldMapper != null) { + analyzer = fieldMapper.indexAnalyzer(); + field = fieldMapper.names().indexName(); } } - if (analyzer==null && request.analyzer() != null) { + if (field == null) { + field = "_all"; + } + if (analyzer == null && request.analyzer() != null) { analyzer = indexService.analysisService().analyzer(request.analyzer()); - } else if (analyzer==null) { + } else if (analyzer == null) { analyzer = indexService.analysisService().defaultIndexAnalyzer(); } if (analyzer == null) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/analyze/AnalyzeRequestBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/analyze/AnalyzeRequestBuilder.java index bc61dcd2be6..2cf16f314d4 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/analyze/AnalyzeRequestBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/indices/analyze/AnalyzeRequestBuilder.java @@ -61,9 +61,4 @@ public class AnalyzeRequestBuilder extends BaseIndicesRequestBuilder() { @Override public void onResponse(AnalyzeResponse response) { diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/indices/analyze/AnalyzeActionTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/indices/analyze/AnalyzeActionTests.java index 9fe8ef92b63..1aec1ae5dd1 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/indices/analyze/AnalyzeActionTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/indices/analyze/AnalyzeActionTests.java @@ -20,7 +20,6 @@ package org.elasticsearch.test.integration.indices.analyze; import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse; -import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; import org.elasticsearch.client.Client; import org.elasticsearch.client.action.admin.indices.analyze.AnalyzeRequestBuilder; import org.elasticsearch.test.integration.AbstractNodesTests; @@ -85,22 +84,21 @@ public class AnalyzeActionTests extends AbstractNodesTests { client.admin().indices().preparePutMapping("test") .setType("document").setSource( - "{\n" + - " \"document\":{\n" + - " \"properties\":{\n" + - " \"simple\":{\n" + - " \"type\":\"string\",\n" + - " \"analyzer\": \"simple\"\n" + - " }\n" + - " }\n" + - " }\n" + - "}" - ).execute().actionGet(); + "{\n" + + " \"document\":{\n" + + " \"properties\":{\n" + + " \"simple\":{\n" + + " \"type\":\"string\",\n" + + " \"analyzer\": \"simple\"\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + ).execute().actionGet(); for (int i = 0; i < 10; i++) { final AnalyzeRequestBuilder requestBuilder = client.admin().indices().prepareAnalyze("test", "THIS IS A TEST"); - requestBuilder.type("document"); - requestBuilder.field("simple"); + requestBuilder.field("document.simple"); AnalyzeResponse analyzeResponse = requestBuilder.execute().actionGet(); assertThat(analyzeResponse.tokens().size(), equalTo(4)); AnalyzeResponse.AnalyzeToken token = analyzeResponse.tokens().get(3); @@ -108,29 +106,5 @@ public class AnalyzeActionTests extends AbstractNodesTests { assertThat(token.startOffset(), equalTo(10)); assertThat(token.endOffset(), equalTo(14)); } - - // test that using the document type only uses the default analyzer - for (int i = 0; i < 10; i++) { - final AnalyzeRequestBuilder requestBuilder = client.admin().indices().prepareAnalyze("test", "THIS IS A TEST"); - requestBuilder.type("document"); - AnalyzeResponse analyzeResponse = requestBuilder.execute().actionGet(); - assertThat(analyzeResponse.tokens().size(), equalTo(1)); - AnalyzeResponse.AnalyzeToken token = analyzeResponse.tokens().get(0); - assertThat(token.term(), equalTo("test")); - assertThat(token.startOffset(), equalTo(10)); - assertThat(token.endOffset(), equalTo(14)); - } - - // test that using the field name only uses the default analyzer - for (int i = 0; i < 10; i++) { - final AnalyzeRequestBuilder requestBuilder = client.admin().indices().prepareAnalyze("test", "THIS IS A TEST"); - requestBuilder.field("simple"); - AnalyzeResponse analyzeResponse = requestBuilder.execute().actionGet(); - assertThat(analyzeResponse.tokens().size(), equalTo(1)); - AnalyzeResponse.AnalyzeToken token = analyzeResponse.tokens().get(0); - assertThat(token.term(), equalTo("test")); - assertThat(token.startOffset(), equalTo(10)); - assertThat(token.endOffset(), equalTo(14)); - } } }