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 24b696795d5..0bf769cc8e6 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 @@ -41,6 +41,7 @@ import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.analysis.*; import org.elasticsearch.index.mapper.FieldMapper; +import org.elasticsearch.index.mapper.internal.AllFieldMapper; import org.elasticsearch.index.service.IndexService; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.indices.analysis.IndicesAnalysisService; @@ -130,7 +131,11 @@ public class TransportAnalyzeAction extends TransportSingleCustomOperationAction } } if (field == null) { - field = "_all"; + if (indexService != null) { + field = indexService.queryParserService().defaultField(); + } else { + field = AllFieldMapper.NAME; + } } if (analyzer == null && request.analyzer() != null) { if (indexService == null) { diff --git a/src/main/java/org/elasticsearch/index/query/FuzzyLikeThisQueryParser.java b/src/main/java/org/elasticsearch/index/query/FuzzyLikeThisQueryParser.java index 60c2c8898c3..cdfc49a50f9 100644 --- a/src/main/java/org/elasticsearch/index/query/FuzzyLikeThisQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/FuzzyLikeThisQueryParser.java @@ -25,7 +25,6 @@ import org.apache.lucene.search.FuzzyLikeThisQuery; import org.apache.lucene.search.Query; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.index.mapper.internal.AllFieldMapper; import java.io.IOException; import java.util.List; @@ -114,7 +113,7 @@ public class FuzzyLikeThisQueryParser implements QueryParser { FuzzyLikeThisQuery query = new FuzzyLikeThisQuery(maxNumTerms, analyzer); if (fields == null) { // add the default _all field - query.addTerms(likeText, AllFieldMapper.NAME, minSimilarity, prefixLength); + query.addTerms(likeText, parseContext.defaultField(), minSimilarity, prefixLength); } else { for (String field : fields) { query.addTerms(likeText, field, minSimilarity, prefixLength); diff --git a/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java b/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java index 142a2d805fd..d4fbd991317 100644 --- a/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java +++ b/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java @@ -35,6 +35,7 @@ import org.elasticsearch.index.analysis.AnalysisService; import org.elasticsearch.index.cache.IndexCache; import org.elasticsearch.index.engine.IndexEngine; import org.elasticsearch.index.mapper.MapperService; +import org.elasticsearch.index.mapper.internal.AllFieldMapper; import org.elasticsearch.index.settings.IndexSettings; import org.elasticsearch.index.similarity.SimilarityService; import org.elasticsearch.indices.query.IndicesQueriesRegistry; @@ -81,6 +82,8 @@ public class IndexQueryParserService extends AbstractIndexComponent { private final Map filterParsers; + private String defaultField; + @Inject public IndexQueryParserService(Index index, @IndexSettings Settings indexSettings, IndicesQueriesRegistry indicesQueriesRegistry, @@ -97,6 +100,8 @@ public class IndexQueryParserService extends AbstractIndexComponent { this.indexCache = indexCache; this.indexEngine = indexEngine; + this.defaultField = indexSettings.get("index.query.default_field", AllFieldMapper.NAME); + List queryParsers = newArrayList(); if (namedQueryParsers != null) { Map queryParserGroups = indexSettings.getGroups(IndexQueryParserService.Defaults.QUERY_PREFIX); @@ -148,6 +153,10 @@ public class IndexQueryParserService extends AbstractIndexComponent { cache.remove(); } + public String defaultField() { + return this.defaultField; + } + public QueryParser queryParser(String name) { return queryParsers.get(name); } diff --git a/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryParser.java b/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryParser.java index 63e2269da0f..3a5afcdca50 100644 --- a/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryParser.java @@ -26,7 +26,6 @@ import org.apache.lucene.search.Query; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.lucene.search.MoreLikeThisQuery; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.index.mapper.internal.AllFieldMapper; import java.io.IOException; import java.util.List; @@ -53,7 +52,7 @@ public class MoreLikeThisQueryParser implements QueryParser { XContentParser parser = parseContext.parser(); MoreLikeThisQuery mltQuery = new MoreLikeThisQuery(); - mltQuery.setMoreLikeFields(new String[]{AllFieldMapper.NAME}); + mltQuery.setMoreLikeFields(new String[]{parseContext.defaultField()}); mltQuery.setSimilarity(parseContext.searchSimilarity()); Analyzer analyzer = null; diff --git a/src/main/java/org/elasticsearch/index/query/QueryParseContext.java b/src/main/java/org/elasticsearch/index/query/QueryParseContext.java index f2902a844bd..dcbc286625b 100644 --- a/src/main/java/org/elasticsearch/index/query/QueryParseContext.java +++ b/src/main/java/org/elasticsearch/index/query/QueryParseContext.java @@ -130,6 +130,10 @@ public class QueryParseContext { return indexQueryParser.indexCache; } + public String defaultField() { + return indexQueryParser.defaultField(); + } + public MapperQueryParser singleQueryParser(QueryParserSettings settings) { queryParser.reset(settings); return queryParser; diff --git a/src/main/java/org/elasticsearch/index/query/QueryStringQueryParser.java b/src/main/java/org/elasticsearch/index/query/QueryStringQueryParser.java index 04b55bfea74..9187f3c44d2 100644 --- a/src/main/java/org/elasticsearch/index/query/QueryStringQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/QueryStringQueryParser.java @@ -34,7 +34,6 @@ import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.index.mapper.internal.AllFieldMapper; import org.elasticsearch.index.query.support.QueryParsers; import java.io.IOException; @@ -68,7 +67,7 @@ public class QueryStringQueryParser implements QueryParser { XContentParser parser = parseContext.parser(); MultiFieldQueryParserSettings qpSettings = new MultiFieldQueryParserSettings(); - qpSettings.defaultField(AllFieldMapper.NAME); + qpSettings.defaultField(parseContext.defaultField()); qpSettings.analyzeWildcard(defaultAnalyzeWildcard); qpSettings.allowLeadingWildcard(defaultAllowLeadingWildcard);