Mappings: Remove type prefix support from field names in queries

This is the first part of #8872.
This commit is contained in:
Ryan Ernst 2015-01-29 16:45:20 -08:00
parent 0f405e9710
commit 6079d88d43
32 changed files with 127 additions and 460 deletions

View File

@ -145,5 +145,40 @@ primary shards.
=== Mappings === Mappings
The setting `index.mapping.allow_type_wrapper` has been removed. Documents should always be sent without the type as the root element. * The setting `index.mapping.allow_type_wrapper` has been removed. Documents should always be sent without the type as the root element.
==== Removed type prefix on field names in queries
Types can no longer be specified on fields within queries. Instead, specify type restrictions in the search request.
The following is an example query in 1.x over types `t1` and `t2`:
`GET
[source,sh]
---------------
curl -XGET 'localhost:9200/index/_search'
{
"query": {
"bool": {
"should": [
{"match": { "t1.field_only_in_t1": "foo" }},
{"match": { "t2.field_only_in_t2": "bar" }}
]
}
}
}
---------------
In 2.0, the query should look like the following:
---------------
curl -XGET 'localhost:9200/index/t1,t2/_search'
{
"query": {
"bool": {
"should": [
{"match": { "field_only_in_t1": "foo" }},
{"match": { "field_only_in_t2": "bar" }}
]
}
}
}
---------------

View File

@ -48,7 +48,6 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import static org.elasticsearch.common.lucene.search.Queries.fixNegativeQueryIfNeeded; import static org.elasticsearch.common.lucene.search.Queries.fixNegativeQueryIfNeeded;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameQuery;
/** /**
* A query parser that uses the {@link MapperService} in order to build smarter * A query parser that uses the {@link MapperService} in order to build smarter
@ -254,17 +253,8 @@ public class MapperQueryParser extends QueryParser {
if (currentMapper != null) { if (currentMapper != null) {
Query query = null; Query query = null;
if (currentMapper.useTermQueryWithQueryString()) { if (currentMapper.useTermQueryWithQueryString()) {
try {
if (fieldMappers.explicitTypeInNameWithDocMapper()) {
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{fieldMappers.docMapper().type()});
try { try {
query = currentMapper.termQuery(queryText, parseContext); query = currentMapper.termQuery(queryText, parseContext);
} finally {
QueryParseContext.setTypes(previousTypes);
}
} else {
query = currentMapper.termQuery(queryText, parseContext);
}
} catch (RuntimeException e) { } catch (RuntimeException e) {
if (settings.lenient()) { if (settings.lenient()) {
return null; return null;
@ -276,7 +266,7 @@ public class MapperQueryParser extends QueryParser {
if (query == null) { if (query == null) {
query = super.getFieldQuery(currentMapper.names().indexName(), queryText, quoted); query = super.getFieldQuery(currentMapper.names().indexName(), queryText, quoted);
} }
return wrapSmartNameQuery(query, fieldMappers, parseContext); return query;
} }
} }
return super.getFieldQuery(field, queryText, quoted); return super.getFieldQuery(field, queryText, quoted);
@ -387,8 +377,7 @@ public class MapperQueryParser extends QueryParser {
} }
try { try {
Query rangeQuery = currentMapper.rangeQuery(part1, part2, startInclusive, endInclusive, parseContext); return currentMapper.rangeQuery(part1, part2, startInclusive, endInclusive, parseContext);
return wrapSmartNameQuery(rangeQuery, fieldMappers, parseContext);
} catch (RuntimeException e) { } catch (RuntimeException e) {
if (settings.lenient()) { if (settings.lenient()) {
return null; return null;
@ -446,8 +435,7 @@ public class MapperQueryParser extends QueryParser {
if (currentMapper != null) { if (currentMapper != null) {
try { try {
//LUCENE 4 UPGRADE I disabled transpositions here by default - maybe this needs to be changed //LUCENE 4 UPGRADE I disabled transpositions here by default - maybe this needs to be changed
Query fuzzyQuery = currentMapper.fuzzyQuery(termStr, Fuzziness.build(minSimilarity), fuzzyPrefixLength, settings.fuzzyMaxExpansions(), false); return currentMapper.fuzzyQuery(termStr, Fuzziness.build(minSimilarity), fuzzyPrefixLength, settings.fuzzyMaxExpansions(), false);
return wrapSmartNameQuery(fuzzyQuery, fieldMappers, parseContext);
} catch (RuntimeException e) { } catch (RuntimeException e) {
if (settings.lenient()) { if (settings.lenient()) {
return null; return null;
@ -525,21 +513,12 @@ public class MapperQueryParser extends QueryParser {
if (currentMapper != null) { if (currentMapper != null) {
Query query = null; Query query = null;
if (currentMapper.useTermQueryWithQueryString()) { if (currentMapper.useTermQueryWithQueryString()) {
if (fieldMappers.explicitTypeInNameWithDocMapper()) {
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{fieldMappers.docMapper().type()});
try {
query = currentMapper.prefixQuery(termStr, multiTermRewriteMethod, parseContext); query = currentMapper.prefixQuery(termStr, multiTermRewriteMethod, parseContext);
} finally {
QueryParseContext.setTypes(previousTypes);
}
} else {
query = currentMapper.prefixQuery(termStr, multiTermRewriteMethod, parseContext);
}
} }
if (query == null) { if (query == null) {
query = getPossiblyAnalyzedPrefixQuery(currentMapper.names().indexName(), termStr); query = getPossiblyAnalyzedPrefixQuery(currentMapper.names().indexName(), termStr);
} }
return wrapSmartNameQuery(query, fieldMappers, parseContext); return query;
} }
} }
return getPossiblyAnalyzedPrefixQuery(field, termStr); return getPossiblyAnalyzedPrefixQuery(field, termStr);
@ -678,7 +657,7 @@ public class MapperQueryParser extends QueryParser {
if (currentMapper != null) { if (currentMapper != null) {
indexedNameField = currentMapper.names().indexName(); indexedNameField = currentMapper.names().indexName();
} }
return wrapSmartNameQuery(getPossiblyAnalyzedWildcardQuery(indexedNameField, termStr), fieldMappers, parseContext); return getPossiblyAnalyzedWildcardQuery(indexedNameField, termStr);
} }
return getPossiblyAnalyzedWildcardQuery(indexedNameField, termStr); return getPossiblyAnalyzedWildcardQuery(indexedNameField, termStr);
} catch (RuntimeException e) { } catch (RuntimeException e) {
@ -813,21 +792,12 @@ public class MapperQueryParser extends QueryParser {
if (currentMapper != null) { if (currentMapper != null) {
Query query = null; Query query = null;
if (currentMapper.useTermQueryWithQueryString()) { if (currentMapper.useTermQueryWithQueryString()) {
if (fieldMappers.explicitTypeInNameWithDocMapper()) {
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{fieldMappers.docMapper().type()});
try {
query = currentMapper.regexpQuery(termStr, RegExp.ALL, maxDeterminizedStates, multiTermRewriteMethod, parseContext); query = currentMapper.regexpQuery(termStr, RegExp.ALL, maxDeterminizedStates, multiTermRewriteMethod, parseContext);
} finally {
QueryParseContext.setTypes(previousTypes);
}
} else {
query = currentMapper.regexpQuery(termStr, RegExp.ALL, maxDeterminizedStates, multiTermRewriteMethod, parseContext);
}
} }
if (query == null) { if (query == null) {
query = super.getRegexpQuery(field, termStr); query = super.getRegexpQuery(field, termStr);
} }
return wrapSmartNameQuery(query, fieldMappers, parseContext); return query;
} }
} }
return super.getRegexpQuery(field, termStr); return super.getRegexpQuery(field, termStr);

View File

@ -66,14 +66,9 @@ import org.elasticsearch.indices.TypeMissingException;
import org.elasticsearch.percolator.PercolatorService; import org.elasticsearch.percolator.PercolatorService;
import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.ScriptService;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.*; import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
@ -91,7 +86,6 @@ public class MapperService extends AbstractIndexComponent {
"_uid", "_id", "_type", "_all", "_analyzer", "_boost", "_parent", "_routing", "_index", "_uid", "_id", "_type", "_all", "_analyzer", "_boost", "_parent", "_routing", "_index",
"_size", "_timestamp", "_ttl" "_size", "_timestamp", "_ttl"
); );
private final AnalysisService analysisService; private final AnalysisService analysisService;
private final IndexFieldDataService fieldDataService; private final IndexFieldDataService fieldDataService;
@ -604,20 +598,27 @@ public class MapperService extends AbstractIndexComponent {
return fullPathObjectMappers.get(path); return fullPathObjectMappers.get(path);
} }
/**
* Returns all the fields that match the given pattern. If the pattern is prefixed with a type
* then the fields will be returned with a type prefix.
*/
public List<String> simpleMatchToIndexNames(String pattern) {
return simpleMatchToIndexNames(pattern, null);
}
/** /**
* Returns all the fields that match the given pattern, with an optional narrowing * Returns all the fields that match the given pattern, with an optional narrowing
* based on a list of types. * based on a list of types.
*/ */
public List<String> simpleMatchToIndexNames(String pattern, @Nullable String[] types) { public List<String> simpleMatchToIndexNames(String pattern, @Nullable String[] types) {
if (types == null || types.length == 0) { if (Regex.isSimpleMatchPattern(pattern) == false) {
return simpleMatchToIndexNames(pattern); // no wildcards
}
if (types.length == 1 && types[0].equals("_all")) {
return simpleMatchToIndexNames(pattern);
}
if (!Regex.isSimpleMatchPattern(pattern)) {
return ImmutableList.of(pattern); return ImmutableList.of(pattern);
} }
if (types == null || types.length == 0 || types.length == 1 && types[0].equals("_all")) {
return fieldMappers.simpleMatchToIndexNames(pattern);
}
List<String> fields = Lists.newArrayList(); List<String> fields = Lists.newArrayList();
for (String type : types) { for (String type : types) {
DocumentMapper possibleDocMapper = mappers.get(type); DocumentMapper possibleDocMapper = mappers.get(type);
@ -630,35 +631,13 @@ public class MapperService extends AbstractIndexComponent {
return fields; return fields;
} }
/**
* Returns all the fields that match the given pattern. If the pattern is prefixed with a type
* then the fields will be returned with a type prefix.
*/
public List<String> simpleMatchToIndexNames(String pattern) {
if (!Regex.isSimpleMatchPattern(pattern)) {
return ImmutableList.of(pattern);
}
int dotIndex = pattern.indexOf('.');
if (dotIndex != -1) {
String possibleType = pattern.substring(0, dotIndex);
DocumentMapper possibleDocMapper = mappers.get(possibleType);
if (possibleDocMapper != null) {
List<String> typedFields = Lists.newArrayList();
for (String indexName : possibleDocMapper.mappers().simpleMatchToIndexNames(pattern)) {
typedFields.add(possibleType + "." + indexName);
}
return typedFields;
}
}
return fieldMappers.simpleMatchToIndexNames(pattern);
}
public SmartNameObjectMapper smartNameObjectMapper(String smartName, @Nullable String[] types) { public SmartNameObjectMapper smartNameObjectMapper(String smartName, @Nullable String[] types) {
if (types == null || types.length == 0) { if (types == null || types.length == 0 || types.length == 1 && types[0].equals("_all")) {
return smartNameObjectMapper(smartName); ObjectMappers mappers = objectMapper(smartName);
if (mappers != null) {
return new SmartNameObjectMapper(mappers.mapper(), guessDocMapper(smartName));
} }
if (types.length == 1 && types[0].equals("_all")) { return null;
return smartNameObjectMapper(smartName);
} }
for (String type : types) { for (String type : types) {
DocumentMapper possibleDocMapper = mappers.get(type); DocumentMapper possibleDocMapper = mappers.get(type);
@ -669,40 +648,6 @@ public class MapperService extends AbstractIndexComponent {
} }
} }
} }
// did not find one, see if its prefixed by type
int dotIndex = smartName.indexOf('.');
if (dotIndex != -1) {
String possibleType = smartName.substring(0, dotIndex);
DocumentMapper possibleDocMapper = mappers.get(possibleType);
if (possibleDocMapper != null) {
String possiblePath = smartName.substring(dotIndex + 1);
ObjectMapper mapper = possibleDocMapper.objectMappers().get(possiblePath);
if (mapper != null) {
return new SmartNameObjectMapper(mapper, possibleDocMapper);
}
}
}
// did not explicitly find one under the types provided, or prefixed by type...
return null;
}
public SmartNameObjectMapper smartNameObjectMapper(String smartName) {
int dotIndex = smartName.indexOf('.');
if (dotIndex != -1) {
String possibleType = smartName.substring(0, dotIndex);
DocumentMapper possibleDocMapper = mappers.get(possibleType);
if (possibleDocMapper != null) {
String possiblePath = smartName.substring(dotIndex + 1);
ObjectMapper mapper = possibleDocMapper.objectMappers().get(possiblePath);
if (mapper != null) {
return new SmartNameObjectMapper(mapper, possibleDocMapper);
}
}
}
ObjectMappers mappers = objectMapper(smartName);
if (mappers != null) {
return new SmartNameObjectMapper(mappers.mapper(), guessDocMapper(smartName));
}
return null; return null;
} }
@ -750,21 +695,6 @@ public class MapperService extends AbstractIndexComponent {
} }
} }
} }
// did not find explicit field in the type provided, see if its prefixed with type
int dotIndex = smartName.indexOf('.');
if (dotIndex != -1) {
String possibleType = smartName.substring(0, dotIndex);
DocumentMapper possibleDocMapper = mappers.get(possibleType);
if (possibleDocMapper != null) {
String possibleName = smartName.substring(dotIndex + 1);
FieldMappers mappers = possibleDocMapper.mappers().smartName(possibleName);
if (mappers != null) {
return mappers;
}
}
}
// we did not find the field mapping in any of the types, so don't go and try to find
// it in other types...
return null; return null;
} }
@ -772,18 +702,6 @@ public class MapperService extends AbstractIndexComponent {
* Same as {@link #smartName(String)}, except it returns just the field mappers. * Same as {@link #smartName(String)}, except it returns just the field mappers.
*/ */
public FieldMappers smartNameFieldMappers(String smartName) { public FieldMappers smartNameFieldMappers(String smartName) {
int dotIndex = smartName.indexOf('.');
if (dotIndex != -1) {
String possibleType = smartName.substring(0, dotIndex);
DocumentMapper possibleDocMapper = mappers.get(possibleType);
if (possibleDocMapper != null) {
String possibleName = smartName.substring(dotIndex + 1);
FieldMappers mappers = possibleDocMapper.mappers().smartName(possibleName);
if (mappers != null) {
return mappers;
}
}
}
FieldMappers mappers = fullName(smartName); FieldMappers mappers = fullName(smartName);
if (mappers != null) { if (mappers != null) {
return mappers; return mappers;
@ -813,21 +731,6 @@ public class MapperService extends AbstractIndexComponent {
} }
} }
} }
// did not find explicit field in the type provided, see if its prefixed with type
int dotIndex = smartName.indexOf('.');
if (dotIndex != -1) {
String possibleType = smartName.substring(0, dotIndex);
DocumentMapper possibleDocMapper = mappers.get(possibleType);
if (possibleDocMapper != null) {
String possibleName = smartName.substring(dotIndex + 1);
FieldMappers mappers = possibleDocMapper.mappers().smartName(possibleName);
if (mappers != null) {
return new SmartNameFieldMappers(this, mappers, possibleDocMapper, true);
}
}
}
// we did not find the field mapping in any of the types, so don't go and try to find
// it in other types...
return null; return null;
} }
@ -844,18 +747,6 @@ public class MapperService extends AbstractIndexComponent {
* <p>If nothing is found, returns null. * <p>If nothing is found, returns null.
*/ */
public SmartNameFieldMappers smartName(String smartName) { public SmartNameFieldMappers smartName(String smartName) {
int dotIndex = smartName.indexOf('.');
if (dotIndex != -1) {
String possibleType = smartName.substring(0, dotIndex);
DocumentMapper possibleDocMapper = mappers.get(possibleType);
if (possibleDocMapper != null) {
String possibleName = smartName.substring(dotIndex + 1);
FieldMappers mappers = possibleDocMapper.mappers().smartName(possibleName);
if (mappers != null) {
return new SmartNameFieldMappers(this, mappers, possibleDocMapper, true);
}
}
}
FieldMappers fieldMappers = fullName(smartName); FieldMappers fieldMappers = fullName(smartName);
if (fieldMappers != null) { if (fieldMappers != null) {
return new SmartNameFieldMappers(this, fieldMappers, null, false); return new SmartNameFieldMappers(this, fieldMappers, null, false);
@ -973,13 +864,11 @@ public class MapperService extends AbstractIndexComponent {
private final MapperService mapperService; private final MapperService mapperService;
private final FieldMappers fieldMappers; private final FieldMappers fieldMappers;
private final DocumentMapper docMapper; private final DocumentMapper docMapper;
private final boolean explicitTypeInName;
public SmartNameFieldMappers(MapperService mapperService, FieldMappers fieldMappers, @Nullable DocumentMapper docMapper, boolean explicitTypeInName) { public SmartNameFieldMappers(MapperService mapperService, FieldMappers fieldMappers, @Nullable DocumentMapper docMapper, boolean explicitTypeInName) {
this.mapperService = mapperService; this.mapperService = mapperService;
this.fieldMappers = fieldMappers; this.fieldMappers = fieldMappers;
this.docMapper = docMapper; this.docMapper = docMapper;
this.explicitTypeInName = explicitTypeInName;
} }
/** /**
@ -1019,17 +908,6 @@ public class MapperService extends AbstractIndexComponent {
return docMapper; return docMapper;
} }
/**
* Returns <tt>true</tt> if the type is explicitly specified in the name.
*/
public boolean explicitTypeInName() {
return this.explicitTypeInName;
}
public boolean explicitTypeInNameWithDocMapper() {
return explicitTypeInName && docMapper != null;
}
/** /**
* The best effort search analyzer associated with this field. * The best effort search analyzer associated with this field.
*/ */
@ -1065,14 +943,6 @@ public class MapperService extends AbstractIndexComponent {
@Override @Override
protected Analyzer getWrappedAnalyzer(String fieldName) { protected Analyzer getWrappedAnalyzer(String fieldName) {
int dotIndex = fieldName.indexOf('.');
if (dotIndex != -1) {
String possibleType = fieldName.substring(0, dotIndex);
DocumentMapper possibleDocMapper = mappers.get(possibleType);
if (possibleDocMapper != null) {
return possibleDocMapper.mappers().searchAnalyzer();
}
}
FieldMappers mappers = fieldMappers.fullName(fieldName); FieldMappers mappers = fieldMappers.fullName(fieldName);
if (mappers != null && mappers.mapper() != null && mappers.mapper().searchAnalyzer() != null) { if (mappers != null && mappers.mapper() != null && mappers.mapper().searchAnalyzer() != null) {
return mappers.mapper().searchAnalyzer(); return mappers.mapper().searchAnalyzer();
@ -1097,14 +967,6 @@ public class MapperService extends AbstractIndexComponent {
@Override @Override
protected Analyzer getWrappedAnalyzer(String fieldName) { protected Analyzer getWrappedAnalyzer(String fieldName) {
int dotIndex = fieldName.indexOf('.');
if (dotIndex != -1) {
String possibleType = fieldName.substring(0, dotIndex);
DocumentMapper possibleDocMapper = mappers.get(possibleType);
if (possibleDocMapper != null) {
return possibleDocMapper.mappers().searchQuoteAnalyzer();
}
}
FieldMappers mappers = fieldMappers.fullName(fieldName); FieldMappers mappers = fieldMappers.fullName(fieldName);
if (mappers != null && mappers.mapper() != null && mappers.mapper().searchQuoteAnalyzer() != null) { if (mappers != null && mappers.mapper() != null && mappers.mapper().searchQuoteAnalyzer() != null) {
return mappers.mapper().searchQuoteAnalyzer(); return mappers.mapper().searchQuoteAnalyzer();

View File

@ -36,8 +36,6 @@ import org.elasticsearch.index.mapper.MapperService;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameQuery;
/** /**
* *
*/ */
@ -224,6 +222,6 @@ public class CommonTermsQueryParser implements QueryParser {
} }
query.setLowFreqMinimumNumberShouldMatch(lowFreqMinimumShouldMatch); query.setLowFreqMinimumNumberShouldMatch(lowFreqMinimumShouldMatch);
query.setHighFreqMinimumNumberShouldMatch(highFreqMinimumShouldMatch); query.setHighFreqMinimumNumberShouldMatch(highFreqMinimumShouldMatch);
return wrapSmartNameQuery(query, smartNameFieldMappers, parseContext); return query;
} }
} }

View File

@ -35,8 +35,6 @@ import org.elasticsearch.index.mapper.internal.FieldNamesFieldMapper;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameFilter;
/** /**
* *
*/ */
@ -129,7 +127,6 @@ public class ExistsFilterParser implements FilterParser {
// its ok to cache under the fieldName cacheKey, since its per segment and the mapping applies to this data on this segment... // its ok to cache under the fieldName cacheKey, since its per segment and the mapping applies to this data on this segment...
Filter filter = parseContext.cacheFilter(boolFilter, new HashedBytesRef("$exists$" + fieldPattern), parseContext.autoFilterCachePolicy()); Filter filter = parseContext.cacheFilter(boolFilter, new HashedBytesRef("$exists$" + fieldPattern), parseContext.autoFilterCachePolicy());
filter = wrapSmartNameFilter(filter, nonNullFieldMappers, parseContext);
if (filterName != null) { if (filterName != null) {
parseContext.addNamedFilter(filterName, filter); parseContext.addNamedFilter(filterName, filter);
} }

View File

@ -33,8 +33,6 @@ import org.elasticsearch.index.mapper.MapperService;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameQuery;
/** /**
* <pre> * <pre>
* { * {
@ -154,10 +152,9 @@ public class FuzzyLikeThisFieldQueryParser implements QueryParser {
} }
assert token == XContentParser.Token.END_OBJECT; assert token == XContentParser.Token.END_OBJECT;
Query query = wrapSmartNameQuery(fuzzyLikeThisQuery, smartNameFieldMappers, parseContext);
if (queryName != null) { if (queryName != null) {
parseContext.addNamedQuery(queryName, query); parseContext.addNamedQuery(queryName, fuzzyLikeThisQuery);
} }
return query; return fuzzyLikeThisQuery;
} }
} }

View File

@ -32,8 +32,6 @@ import org.elasticsearch.index.query.support.QueryParsers;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameQuery;
/** /**
* *
*/ */
@ -127,7 +125,6 @@ public class FuzzyQueryParser implements QueryParser {
} }
query.setBoost(boost); query.setBoost(boost);
query = wrapSmartNameQuery(query, smartNameFieldMappers, parseContext);
if (queryName != null) { if (queryName != null) {
parseContext.addNamedQuery(queryName, query); parseContext.addNamedQuery(queryName, query);
} }

View File

@ -36,8 +36,6 @@ import org.elasticsearch.index.search.geo.IndexedGeoBoundingBoxFilter;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameFilter;
/** /**
* *
*/ */
@ -192,7 +190,6 @@ public class GeoBoundingBoxFilterParser implements FilterParser {
if (cache != null) { if (cache != null) {
filter = parseContext.cacheFilter(filter, cacheKey, cache); filter = parseContext.cacheFilter(filter, cacheKey, cache);
} }
filter = wrapSmartNameFilter(filter, smartMappers, parseContext);
if (filterName != null) { if (filterName != null) {
parseContext.addNamedFilter(filterName, filter); parseContext.addNamedFilter(filterName, filter);
} }

View File

@ -37,8 +37,6 @@ import org.elasticsearch.index.search.geo.GeoDistanceFilter;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameFilter;
/** /**
* <pre> * <pre>
* { * {
@ -171,7 +169,6 @@ public class GeoDistanceFilterParser implements FilterParser {
if (cache != null) { if (cache != null) {
filter = parseContext.cacheFilter(filter, cacheKey, cache); filter = parseContext.cacheFilter(filter, cacheKey, cache);
} }
filter = wrapSmartNameFilter(filter, smartMappers, parseContext);
if (filterName != null) { if (filterName != null) {
parseContext.addNamedFilter(filterName, filter); parseContext.addNamedFilter(filterName, filter);
} }

View File

@ -37,8 +37,6 @@ import org.elasticsearch.index.search.geo.GeoDistanceRangeFilter;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameFilter;
/** /**
* <pre> * <pre>
* { * {
@ -211,7 +209,6 @@ public class GeoDistanceRangeFilterParser implements FilterParser {
if (cache != null) { if (cache != null) {
filter = parseContext.cacheFilter(filter, cacheKey, cache); filter = parseContext.cacheFilter(filter, cacheKey, cache);
} }
filter = wrapSmartNameFilter(filter, smartMappers, parseContext);
if (filterName != null) { if (filterName != null) {
parseContext.addNamedFilter(filterName, filter); parseContext.addNamedFilter(filterName, filter);
} }

View File

@ -38,8 +38,6 @@ import org.elasticsearch.index.search.geo.GeoPolygonFilter;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameFilter;
/** /**
* <pre> * <pre>
* { * {
@ -157,7 +155,6 @@ public class GeoPolygonFilterParser implements FilterParser {
if (cache != null) { if (cache != null) {
filter = parseContext.cacheFilter(filter, cacheKey, cache); filter = parseContext.cacheFilter(filter, cacheKey, cache);
} }
filter = wrapSmartNameFilter(filter, smartMappers, parseContext);
if (filterName != null) { if (filterName != null) {
parseContext.addNamedFilter(filterName, filter); parseContext.addNamedFilter(filterName, filter);
} }

View File

@ -40,8 +40,6 @@ import org.elasticsearch.index.search.shape.ShapeFetchService;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameFilter;
/** /**
* {@link FilterParser} for filtering Documents based on {@link Shape}s. * {@link FilterParser} for filtering Documents based on {@link Shape}s.
* <p/> * <p/>
@ -199,8 +197,6 @@ public class GeoShapeFilterParser implements FilterParser {
filter = parseContext.cacheFilter(filter, cacheKey, cache); filter = parseContext.cacheFilter(filter, cacheKey, cache);
} }
filter = wrapSmartNameFilter(filter, smartNameFieldMappers, parseContext);
if (filterName != null) { if (filterName != null) {
parseContext.addNamedFilter(filterName, filter); parseContext.addNamedFilter(filterName, filter);
} }

View File

@ -36,8 +36,6 @@ import org.elasticsearch.index.mapper.internal.FieldNamesFieldMapper;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameFilter;
/** /**
* *
*/ */
@ -185,7 +183,6 @@ public class MissingFilterParser implements FilterParser {
return null; return null;
} }
filter = wrapSmartNameFilter(filter, nonNullFieldMappers, parseContext);
if (filterName != null) { if (filterName != null) {
parseContext.addNamedFilter(filterName, existenceFilter); parseContext.addNamedFilter(filterName, existenceFilter);
} }

View File

@ -31,8 +31,6 @@ import org.elasticsearch.index.mapper.MapperService;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameFilter;
/** /**
* *
*/ */
@ -86,16 +84,7 @@ public class PrefixFilterParser implements FilterParser {
MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName); MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) { if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) {
if (smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{smartNameFieldMappers.docMapper().type()});
try {
filter = smartNameFieldMappers.mapper().prefixFilter(value, parseContext); filter = smartNameFieldMappers.mapper().prefixFilter(value, parseContext);
} finally {
QueryParseContext.setTypes(previousTypes);
}
} else {
filter = smartNameFieldMappers.mapper().prefixFilter(value, parseContext);
}
} }
if (filter == null) { if (filter == null) {
filter = new PrefixFilter(new Term(fieldName, BytesRefs.toBytesRef(value))); filter = new PrefixFilter(new Term(fieldName, BytesRefs.toBytesRef(value)));
@ -104,8 +93,6 @@ public class PrefixFilterParser implements FilterParser {
if (cache != null) { if (cache != null) {
filter = parseContext.cacheFilter(filter, cacheKey, cache); filter = parseContext.cacheFilter(filter, cacheKey, cache);
} }
filter = wrapSmartNameFilter(filter, smartNameFieldMappers, parseContext);
if (filterName != null) { if (filterName != null) {
parseContext.addNamedFilter(filterName, filter); parseContext.addNamedFilter(filterName, filter);
} }

View File

@ -31,8 +31,6 @@ import org.elasticsearch.index.query.support.QueryParsers;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameQuery;
/** /**
* *
*/ */
@ -100,16 +98,7 @@ public class PrefixQueryParser implements QueryParser {
Query query = null; Query query = null;
MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName); MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) { if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) {
if (smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{smartNameFieldMappers.docMapper().type()});
try {
query = smartNameFieldMappers.mapper().prefixQuery(value, method, parseContext); query = smartNameFieldMappers.mapper().prefixQuery(value, method, parseContext);
} finally {
QueryParseContext.setTypes(previousTypes);
}
} else {
query = smartNameFieldMappers.mapper().prefixQuery(value, method, parseContext);
}
} }
if (query == null) { if (query == null) {
PrefixQuery prefixQuery = new PrefixQuery(new Term(fieldName, BytesRefs.toBytesRef(value))); PrefixQuery prefixQuery = new PrefixQuery(new Term(fieldName, BytesRefs.toBytesRef(value)));
@ -119,7 +108,6 @@ public class PrefixQueryParser implements QueryParser {
query = prefixQuery; query = prefixQuery;
} }
query.setBoost(boost); query.setBoost(boost);
query = wrapSmartNameQuery(query, smartNameFieldMappers, parseContext);
if (queryName != null) { if (queryName != null) {
parseContext.addNamedQuery(queryName, query); parseContext.addNamedQuery(queryName, query);
} }

View File

@ -36,8 +36,6 @@ import org.joda.time.DateTimeZone;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameFilter;
/** /**
* *
*/ */
@ -176,7 +174,6 @@ public class RangeFilterParser implements FilterParser {
filter = parseContext.cacheFilter(filter, cacheKey, cache); filter = parseContext.cacheFilter(filter, cacheKey, cache);
} }
filter = wrapSmartNameFilter(filter, smartNameFieldMappers, parseContext);
if (filterName != null) { if (filterName != null) {
parseContext.addNamedFilter(filterName, filter); parseContext.addNamedFilter(filterName, filter);
} }

View File

@ -33,8 +33,6 @@ import org.joda.time.DateTimeZone;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameQuery;
/** /**
* *
*/ */
@ -143,7 +141,6 @@ public class RangeQueryParser implements QueryParser {
query = new TermRangeQuery(fieldName, BytesRefs.toBytesRef(from), BytesRefs.toBytesRef(to), includeLower, includeUpper); query = new TermRangeQuery(fieldName, BytesRefs.toBytesRef(from), BytesRefs.toBytesRef(to), includeLower, includeUpper);
} }
query.setBoost(boost); query.setBoost(boost);
query = wrapSmartNameQuery(query, smartNameFieldMappers, parseContext);
if (queryName != null) { if (queryName != null) {
parseContext.addNamedQuery(queryName, query); parseContext.addNamedQuery(queryName, query);
} }

View File

@ -32,8 +32,6 @@ import org.elasticsearch.index.mapper.MapperService;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameFilter;
/** /**
* *
*/ */
@ -116,16 +114,7 @@ public class RegexpFilterParser implements FilterParser {
MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName); MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) { if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) {
if (smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{smartNameFieldMappers.docMapper().type()});
try {
filter = smartNameFieldMappers.mapper().regexpFilter(value, flagsValue, maxDeterminizedStates, parseContext); filter = smartNameFieldMappers.mapper().regexpFilter(value, flagsValue, maxDeterminizedStates, parseContext);
} finally {
QueryParseContext.setTypes(previousTypes);
}
} else {
filter = smartNameFieldMappers.mapper().regexpFilter(value, flagsValue, maxDeterminizedStates, parseContext);
}
} }
if (filter == null) { if (filter == null) {
filter = new RegexpFilter(new Term(fieldName, BytesRefs.toBytesRef(value)), flagsValue, maxDeterminizedStates); filter = new RegexpFilter(new Term(fieldName, BytesRefs.toBytesRef(value)), flagsValue, maxDeterminizedStates);
@ -135,7 +124,6 @@ public class RegexpFilterParser implements FilterParser {
filter = parseContext.cacheFilter(filter, cacheKey, cache); filter = parseContext.cacheFilter(filter, cacheKey, cache);
} }
filter = wrapSmartNameFilter(filter, smartNameFieldMappers, parseContext);
if (filterName != null) { if (filterName != null) {
parseContext.addNamedFilter(filterName, filter); parseContext.addNamedFilter(filterName, filter);
} }

View File

@ -33,8 +33,6 @@ import org.elasticsearch.index.query.support.QueryParsers;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameQuery;
/** /**
* *
*/ */
@ -112,16 +110,7 @@ public class RegexpQueryParser implements QueryParser {
Query query = null; Query query = null;
MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName); MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) { if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) {
if (smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{smartNameFieldMappers.docMapper().type()});
try {
query = smartNameFieldMappers.mapper().regexpQuery(value, flagsValue, maxDeterminizedStates, method, parseContext); query = smartNameFieldMappers.mapper().regexpQuery(value, flagsValue, maxDeterminizedStates, method, parseContext);
} finally {
QueryParseContext.setTypes(previousTypes);
}
} else {
query = smartNameFieldMappers.mapper().regexpQuery(value, flagsValue, maxDeterminizedStates, method, parseContext);
}
} }
if (query == null) { if (query == null) {
RegexpQuery regexpQuery = new RegexpQuery(new Term(fieldName, BytesRefs.toBytesRef(value)), flagsValue, maxDeterminizedStates); RegexpQuery regexpQuery = new RegexpQuery(new Term(fieldName, BytesRefs.toBytesRef(value)), flagsValue, maxDeterminizedStates);
@ -131,7 +120,6 @@ public class RegexpQueryParser implements QueryParser {
query = regexpQuery; query = regexpQuery;
} }
query.setBoost(boost); query.setBoost(boost);
query = wrapSmartNameQuery(query, smartNameFieldMappers, parseContext);
if (queryName != null) { if (queryName != null) {
parseContext.addNamedQuery(queryName, query); parseContext.addNamedQuery(queryName, query);
} }

View File

@ -31,8 +31,6 @@ import org.elasticsearch.index.mapper.MapperService;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameFilter;
/** /**
* *
*/ */
@ -111,16 +109,7 @@ public class TermFilterParser implements FilterParser {
Filter filter = null; Filter filter = null;
MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName); MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) { if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) {
if (smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{smartNameFieldMappers.docMapper().type()});
try {
filter = smartNameFieldMappers.mapper().termFilter(value, parseContext); filter = smartNameFieldMappers.mapper().termFilter(value, parseContext);
} finally {
QueryParseContext.setTypes(previousTypes);
}
} else {
filter = smartNameFieldMappers.mapper().termFilter(value, parseContext);
}
} }
if (filter == null) { if (filter == null) {
filter = new TermFilter(new Term(fieldName, BytesRefs.toBytesRef(value))); filter = new TermFilter(new Term(fieldName, BytesRefs.toBytesRef(value)));
@ -130,7 +119,6 @@ public class TermFilterParser implements FilterParser {
filter = parseContext.cacheFilter(filter, cacheKey, cache); filter = parseContext.cacheFilter(filter, cacheKey, cache);
} }
filter = wrapSmartNameFilter(filter, smartNameFieldMappers, parseContext);
if (filterName != null) { if (filterName != null) {
parseContext.addNamedFilter(filterName, filter); parseContext.addNamedFilter(filterName, filter);
} }

View File

@ -29,8 +29,6 @@ import org.elasticsearch.index.mapper.MapperService;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameQuery;
/** /**
* *
*/ */
@ -94,22 +92,12 @@ public class TermQueryParser implements QueryParser {
Query query = null; Query query = null;
MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName); MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) { if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) {
if (smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{smartNameFieldMappers.docMapper().type()});
try {
query = smartNameFieldMappers.mapper().termQuery(value, parseContext); query = smartNameFieldMappers.mapper().termQuery(value, parseContext);
} finally {
QueryParseContext.setTypes(previousTypes);
}
} else {
query = smartNameFieldMappers.mapper().termQuery(value, parseContext);
}
} }
if (query == null) { if (query == null) {
query = new TermQuery(new Term(fieldName, BytesRefs.toBytesRef(value))); query = new TermQuery(new Term(fieldName, BytesRefs.toBytesRef(value)));
} }
query.setBoost(boost); query.setBoost(boost);
query = wrapSmartNameQuery(query, smartNameFieldMappers, parseContext);
if (queryName != null) { if (queryName != null) {
parseContext.addNamedQuery(queryName, query); parseContext.addNamedQuery(queryName, query);
} }

View File

@ -47,8 +47,6 @@ import org.elasticsearch.indices.cache.filter.terms.TermsLookup;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameFilter;
/** /**
* *
*/ */
@ -168,16 +166,11 @@ public class TermsFilterParser implements FilterParser {
FieldMapper<?> fieldMapper = null; FieldMapper<?> fieldMapper = null;
smartNameFieldMappers = parseContext.smartFieldMappers(fieldName); smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
String[] previousTypes = null;
if (smartNameFieldMappers != null) { if (smartNameFieldMappers != null) {
if (smartNameFieldMappers.hasMapper()) { if (smartNameFieldMappers.hasMapper()) {
fieldMapper = smartNameFieldMappers.mapper(); fieldMapper = smartNameFieldMappers.mapper();
fieldName = fieldMapper.names().indexName(); fieldName = fieldMapper.names().indexName();
} }
// if we have a doc mapper, its explicit type, mark it
if (smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{smartNameFieldMappers.docMapper().type()});
}
} }
if (lookupId != null) { if (lookupId != null) {
@ -193,7 +186,6 @@ public class TermsFilterParser implements FilterParser {
return Queries.MATCH_NO_FILTER; return Queries.MATCH_NO_FILTER;
} }
try {
Filter filter; Filter filter;
if (EXECUTION_VALUE_PLAIN.equals(execution)) { if (EXECUTION_VALUE_PLAIN.equals(execution)) {
if (fieldMapper != null) { if (fieldMapper != null) {
@ -293,15 +285,9 @@ public class TermsFilterParser implements FilterParser {
filter = parseContext.cacheFilter(filter, cacheKey, cache); filter = parseContext.cacheFilter(filter, cacheKey, cache);
} }
filter = wrapSmartNameFilter(filter, smartNameFieldMappers, parseContext);
if (filterName != null) { if (filterName != null) {
parseContext.addNamedFilter(filterName, filter); parseContext.addNamedFilter(filterName, filter);
} }
return filter; return filter;
} finally {
if (smartNameFieldMappers != null && smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
QueryParseContext.setTypes(previousTypes);
}
}
} }
} }

View File

@ -35,7 +35,6 @@ import java.util.List;
import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Lists.newArrayList;
import static org.elasticsearch.common.lucene.search.Queries.fixNegativeQueryIfNeeded; import static org.elasticsearch.common.lucene.search.Queries.fixNegativeQueryIfNeeded;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameQuery;
/** /**
* <pre> * <pre>
@ -114,12 +113,9 @@ public class TermsQueryParser implements QueryParser {
String[] previousTypes = null; String[] previousTypes = null;
if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) { if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) {
mapper = smartNameFieldMappers.mapper(); mapper = smartNameFieldMappers.mapper();
if (smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{smartNameFieldMappers.docMapper().type()});
}
} }
try {
BooleanQuery booleanQuery = new BooleanQuery(disableCoord); BooleanQuery booleanQuery = new BooleanQuery(disableCoord);
for (Object value : values) { for (Object value : values) {
if (mapper != null) { if (mapper != null) {
@ -130,16 +126,11 @@ public class TermsQueryParser implements QueryParser {
} }
booleanQuery.setBoost(boost); booleanQuery.setBoost(boost);
Queries.applyMinimumShouldMatch(booleanQuery, minimumShouldMatch); Queries.applyMinimumShouldMatch(booleanQuery, minimumShouldMatch);
Query query = wrapSmartNameQuery(fixNegativeQueryIfNeeded(booleanQuery), smartNameFieldMappers, parseContext); Query query = fixNegativeQueryIfNeeded(booleanQuery);
if (queryName != null) { if (queryName != null) {
parseContext.addNamedQuery(queryName, query); parseContext.addNamedQuery(queryName, query);
} }
return query; return query;
} finally {
if (smartNameFieldMappers != null && smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
QueryParseContext.setTypes(previousTypes);
}
}
} }
} }

View File

@ -30,8 +30,6 @@ import org.elasticsearch.index.query.support.QueryParsers;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameQuery;
/** /**
* *
*/ */
@ -107,10 +105,9 @@ public class WildcardQueryParser implements QueryParser {
QueryParsers.setRewriteMethod(wildcardQuery, rewriteMethod); QueryParsers.setRewriteMethod(wildcardQuery, rewriteMethod);
wildcardQuery.setRewriteMethod(QueryParsers.parseRewriteMethod(rewriteMethod)); wildcardQuery.setRewriteMethod(QueryParsers.parseRewriteMethod(rewriteMethod));
wildcardQuery.setBoost(boost); wildcardQuery.setBoost(boost);
Query query = wrapSmartNameQuery(wildcardQuery, smartNameFieldMappers, parseContext);
if (queryName != null) { if (queryName != null) {
parseContext.addNamedQuery(queryName, query); parseContext.addNamedQuery(queryName, wildcardQuery);
} }
return query; return wildcardQuery;
} }
} }

View File

@ -93,30 +93,4 @@ public final class QueryParsers {
throw new ElasticsearchIllegalArgumentException("Failed to parse rewrite_method [" + rewriteMethod + "]"); throw new ElasticsearchIllegalArgumentException("Failed to parse rewrite_method [" + rewriteMethod + "]");
} }
public static Query wrapSmartNameQuery(Query query, @Nullable MapperService.SmartNameFieldMappers smartFieldMappers,
QueryParseContext parseContext) {
if (query == null) {
return null;
}
if (smartFieldMappers == null) {
return query;
}
if (!smartFieldMappers.explicitTypeInNameWithDocMapper()) {
return query;
}
DocumentMapper docMapper = smartFieldMappers.docMapper();
return new FilteredQuery(query, parseContext.cacheFilter(docMapper.typeFilter(), null, parseContext.autoFilterCachePolicy()));
}
public static Filter wrapSmartNameFilter(Filter filter, @Nullable MapperService.SmartNameFieldMappers smartFieldMappers,
QueryParseContext parseContext) {
if (smartFieldMappers == null) {
return filter;
}
if (!smartFieldMappers.explicitTypeInNameWithDocMapper()) {
return filter;
}
DocumentMapper docMapper = smartFieldMappers.docMapper();
return new AndFilter(ImmutableList.of(parseContext.cacheFilter(docMapper.typeFilter(), null, parseContext.autoFilterCachePolicy()), filter));
}
} }

View File

@ -39,8 +39,6 @@ import org.elasticsearch.index.query.support.QueryParsers;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameQuery;
public class MatchQuery { public class MatchQuery {
public static enum Type { public static enum Type {
@ -176,28 +174,15 @@ public class MatchQuery {
} }
if (mapper != null && mapper.useTermQueryWithQueryString() && !forceAnalyzeQueryString()) { if (mapper != null && mapper.useTermQueryWithQueryString() && !forceAnalyzeQueryString()) {
if (smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{smartNameFieldMappers.docMapper().type()});
try { try {
return wrapSmartNameQuery(mapper.termQuery(value, parseContext), smartNameFieldMappers, parseContext); return mapper.termQuery(value, parseContext);
} catch (RuntimeException e) {
if (lenient) {
return null;
}
throw e;
} finally {
QueryParseContext.setTypes(previousTypes);
}
} else {
try {
return wrapSmartNameQuery(mapper.termQuery(value, parseContext), smartNameFieldMappers, parseContext);
} catch (RuntimeException e) { } catch (RuntimeException e) {
if (lenient) { if (lenient) {
return null; return null;
} }
throw e; throw e;
} }
}
} }
Analyzer analyzer = getAnalyzer(mapper, smartNameFieldMappers); Analyzer analyzer = getAnalyzer(mapper, smartNameFieldMappers);
MatchQueryBuilder builder = new MatchQueryBuilder(analyzer, mapper); MatchQueryBuilder builder = new MatchQueryBuilder(analyzer, mapper);
@ -225,7 +210,7 @@ public class MatchQuery {
if (query == null) { if (query == null) {
return zeroTermsQuery(); return zeroTermsQuery();
} else { } else {
return wrapSmartNameQuery(query, smartNameFieldMappers, parseContext); return query;
} }
} }

View File

@ -135,15 +135,7 @@ public class HighlightPhase extends AbstractComponent implements FetchSubPhase {
private FieldMapper<?> getMapperForField(String fieldName, SearchContext searchContext, HitContext hitContext) { private FieldMapper<?> getMapperForField(String fieldName, SearchContext searchContext, HitContext hitContext) {
DocumentMapper documentMapper = searchContext.mapperService().documentMapper(hitContext.hit().type()); DocumentMapper documentMapper = searchContext.mapperService().documentMapper(hitContext.hit().type());
FieldMapper<?> mapper = documentMapper.mappers().smartNameFieldMapper(fieldName); // TODO: no need to lookup the doc mapper with unambiguous field names? just look at the mapper service
if (mapper == null) { return documentMapper.mappers().smartNameFieldMapper(fieldName);
MapperService.SmartNameFieldMappers fullMapper = searchContext.mapperService().smartName(fieldName);
if (fullMapper == null || !fullMapper.hasDocMapper() || fullMapper.docMapper().type().equals(hitContext.hit().type())) {
return null;
}
mapper = fullMapper.mapper();
}
return mapper;
} }
} }

View File

@ -825,14 +825,11 @@ public class CountQueryTests extends ElasticsearchIntegrationTest {
CountResponse response = client().prepareCount("test") CountResponse response = client().prepareCount("test")
.setQuery(QueryBuilders.spanOrQuery().clause(QueryBuilders.spanTermQuery("description", "bar"))).get(); .setQuery(QueryBuilders.spanOrQuery().clause(QueryBuilders.spanTermQuery("description", "bar"))).get();
assertHitCount(response, 1l); assertHitCount(response, 1l);
response = client().prepareCount("test")
.setQuery(QueryBuilders.spanOrQuery().clause(QueryBuilders.spanTermQuery("test.description", "bar"))).get();
assertHitCount(response, 1l);
response = client().prepareCount("test").setQuery( response = client().prepareCount("test").setQuery(
QueryBuilders.spanNearQuery() QueryBuilders.spanNearQuery()
.clause(QueryBuilders.spanTermQuery("description", "foo")) .clause(QueryBuilders.spanTermQuery("description", "foo"))
.clause(QueryBuilders.spanTermQuery("test.description", "other")) .clause(QueryBuilders.spanTermQuery("description", "other"))
.slop(3)).get(); .slop(3)).get();
assertHitCount(response, 3l); assertHitCount(response, 3l);
} }

View File

@ -61,7 +61,7 @@ public class SimpleNestedTests extends ElasticsearchIntegrationTest {
// check on no data, see it works // check on no data, see it works
SearchResponse searchResponse = client().prepareSearch("test").setQuery(termQuery("_all", "n_value1_1")).execute().actionGet(); SearchResponse searchResponse = client().prepareSearch("test").setQuery(termQuery("_all", "n_value1_1")).execute().actionGet();
assertThat(searchResponse.getHits().totalHits(), equalTo(0l)); assertThat(searchResponse.getHits().totalHits(), equalTo(0l));
searchResponse = client().prepareSearch("test").setQuery(termQuery("nested1.n_field1", "n_value1_1")).execute().actionGet(); searchResponse = client().prepareSearch("test").setQuery(termQuery("n_field1", "n_value1_1")).execute().actionGet();
assertThat(searchResponse.getHits().totalHits(), equalTo(0l)); assertThat(searchResponse.getHits().totalHits(), equalTo(0l));
client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject() client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject()
@ -91,21 +91,21 @@ public class SimpleNestedTests extends ElasticsearchIntegrationTest {
// check that _all is working on nested docs // check that _all is working on nested docs
searchResponse = client().prepareSearch("test").setQuery(termQuery("_all", "n_value1_1")).execute().actionGet(); searchResponse = client().prepareSearch("test").setQuery(termQuery("_all", "n_value1_1")).execute().actionGet();
assertThat(searchResponse.getHits().totalHits(), equalTo(1l)); assertThat(searchResponse.getHits().totalHits(), equalTo(1l));
searchResponse = client().prepareSearch("test").setQuery(termQuery("nested1.n_field1", "n_value1_1")).execute().actionGet(); searchResponse = client().prepareSearch("test").setQuery(termQuery("n_field1", "n_value1_1")).execute().actionGet();
assertThat(searchResponse.getHits().totalHits(), equalTo(0l)); assertThat(searchResponse.getHits().totalHits(), equalTo(0l));
// search for something that matches the nested doc, and see that we don't find the nested doc // search for something that matches the nested doc, and see that we don't find the nested doc
searchResponse = client().prepareSearch("test").setQuery(matchAllQuery()).get(); searchResponse = client().prepareSearch("test").setQuery(matchAllQuery()).get();
assertThat(searchResponse.getHits().totalHits(), equalTo(1l)); assertThat(searchResponse.getHits().totalHits(), equalTo(1l));
searchResponse = client().prepareSearch("test").setQuery(termQuery("nested1.n_field1", "n_value1_1")).get(); searchResponse = client().prepareSearch("test").setQuery(termQuery("n_field1", "n_value1_1")).get();
assertThat(searchResponse.getHits().totalHits(), equalTo(0l)); assertThat(searchResponse.getHits().totalHits(), equalTo(0l));
// now, do a nested query // now, do a nested query
searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1", termQuery("nested1.n_field1", "n_value1_1"))).get(); searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1", termQuery("n_field1", "n_value1_1"))).get();
assertNoFailures(searchResponse); assertNoFailures(searchResponse);
assertThat(searchResponse.getHits().totalHits(), equalTo(1l)); assertThat(searchResponse.getHits().totalHits(), equalTo(1l));
searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1", termQuery("nested1.n_field1", "n_value1_1"))).setSearchType(SearchType.DFS_QUERY_THEN_FETCH).get(); searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1", termQuery("n_field1", "n_value1_1"))).setSearchType(SearchType.DFS_QUERY_THEN_FETCH).get();
assertNoFailures(searchResponse); assertNoFailures(searchResponse);
assertThat(searchResponse.getHits().totalHits(), equalTo(1l)); assertThat(searchResponse.getHits().totalHits(), equalTo(1l));
@ -130,19 +130,19 @@ public class SimpleNestedTests extends ElasticsearchIntegrationTest {
assertDocumentCount("test", 6); assertDocumentCount("test", 6);
searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1", searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1",
boolQuery().must(termQuery("nested1.n_field1", "n_value1_1")).must(termQuery("nested1.n_field2", "n_value2_1")))).execute().actionGet(); boolQuery().must(termQuery("n_field1", "n_value1_1")).must(termQuery("n_field2", "n_value2_1")))).execute().actionGet();
assertNoFailures(searchResponse); assertNoFailures(searchResponse);
assertThat(searchResponse.getHits().totalHits(), equalTo(1l)); assertThat(searchResponse.getHits().totalHits(), equalTo(1l));
// filter // filter
searchResponse = client().prepareSearch("test").setQuery(filteredQuery(matchAllQuery(), nestedFilter("nested1", searchResponse = client().prepareSearch("test").setQuery(filteredQuery(matchAllQuery(), nestedFilter("nested1",
boolQuery().must(termQuery("nested1.n_field1", "n_value1_1")).must(termQuery("nested1.n_field2", "n_value2_1"))))).execute().actionGet(); boolQuery().must(termQuery("n_field1", "n_value1_1")).must(termQuery("n_field2", "n_value2_1"))))).execute().actionGet();
assertNoFailures(searchResponse); assertNoFailures(searchResponse);
assertThat(searchResponse.getHits().totalHits(), equalTo(1l)); assertThat(searchResponse.getHits().totalHits(), equalTo(1l));
// check with type prefix // check with type prefix
searchResponse = client().prepareSearch("test").setQuery(nestedQuery("type1.nested1", searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1",
boolQuery().must(termQuery("nested1.n_field1", "n_value1_1")).must(termQuery("nested1.n_field2", "n_value2_1")))).execute().actionGet(); boolQuery().must(termQuery("n_field1", "n_value1_1")).must(termQuery("n_field2", "n_value2_1")))).execute().actionGet();
assertNoFailures(searchResponse); assertNoFailures(searchResponse);
assertThat(searchResponse.getHits().totalHits(), equalTo(1l)); assertThat(searchResponse.getHits().totalHits(), equalTo(1l));
@ -154,11 +154,11 @@ public class SimpleNestedTests extends ElasticsearchIntegrationTest {
flush(); flush();
assertDocumentCount("test", 3); assertDocumentCount("test", 3);
searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1", termQuery("nested1.n_field1", "n_value1_1"))).execute().actionGet(); searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1", termQuery("n_field1", "n_value1_1"))).execute().actionGet();
assertNoFailures(searchResponse); assertNoFailures(searchResponse);
assertThat(searchResponse.getHits().totalHits(), equalTo(1l)); assertThat(searchResponse.getHits().totalHits(), equalTo(1l));
searchResponse = client().prepareSearch("test").setTypes("type1", "type2").setQuery(nestedQuery("nested1", termQuery("nested1.n_field1", "n_value1_1"))).execute().actionGet(); searchResponse = client().prepareSearch("test").setTypes("type1", "type2").setQuery(nestedQuery("nested1", termQuery("n_field1", "n_value1_1"))).execute().actionGet();
assertNoFailures(searchResponse); assertNoFailures(searchResponse);
assertThat(searchResponse.getHits().totalHits(), equalTo(1l)); assertThat(searchResponse.getHits().totalHits(), equalTo(1l));
} }

View File

@ -250,15 +250,6 @@ public class SimpleChildQuerySearchTests extends ElasticsearchIntegrationTest {
assertThat(searchResponse.getHits().getAt(0).field("_parent").value().toString(), equalTo("p1")); assertThat(searchResponse.getHits().getAt(0).field("_parent").value().toString(), equalTo("p1"));
// TEST matching on parent // TEST matching on parent
searchResponse = client().prepareSearch("test").setQuery(termQuery("child._parent", "p1")).addFields("_parent").execute()
.actionGet();
assertNoFailures(searchResponse);
assertThat(searchResponse.getHits().totalHits(), equalTo(2l));
assertThat(searchResponse.getHits().getAt(0).id(), anyOf(equalTo("c1"), equalTo("c2")));
assertThat(searchResponse.getHits().getAt(0).field("_parent").value().toString(), equalTo("p1"));
assertThat(searchResponse.getHits().getAt(1).id(), anyOf(equalTo("c1"), equalTo("c2")));
assertThat(searchResponse.getHits().getAt(1).field("_parent").value().toString(), equalTo("p1"));
searchResponse = client().prepareSearch("test").setQuery(termQuery("_parent", "p1")).addFields("_parent").get(); searchResponse = client().prepareSearch("test").setQuery(termQuery("_parent", "p1")).addFields("_parent").get();
assertNoFailures(searchResponse); assertNoFailures(searchResponse);
assertThat(searchResponse.getHits().totalHits(), equalTo(2l)); assertThat(searchResponse.getHits().totalHits(), equalTo(2l));

View File

@ -1492,14 +1492,10 @@ public class SearchQueryTests extends ElasticsearchIntegrationTest {
.setQuery(spanOrQuery().clause(spanTermQuery("description", "bar"))).get(); .setQuery(spanOrQuery().clause(spanTermQuery("description", "bar"))).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
searchResponse = client().prepareSearch("test")
.setQuery(spanOrQuery().clause(spanTermQuery("test.description", "bar"))).get();
assertHitCount(searchResponse, 1l);
searchResponse = client().prepareSearch("test").setQuery( searchResponse = client().prepareSearch("test").setQuery(
spanNearQuery() spanNearQuery()
.clause(spanTermQuery("description", "foo")) .clause(spanTermQuery("description", "foo"))
.clause(spanTermQuery("test.description", "other")) .clause(spanTermQuery("description", "other"))
.slop(3)).get(); .slop(3)).get();
assertHitCount(searchResponse, 3l); assertHitCount(searchResponse, 3l);
} }
@ -2097,19 +2093,19 @@ public class SearchQueryTests extends ElasticsearchIntegrationTest {
assertHitCount(searchResponse, 2); assertHitCount(searchResponse, 2);
} }
{ {
SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.queryStringQuery("\"one two\"").field("product.desc")).get(); SearchResponse searchResponse = client().prepareSearch("test").setTypes("product").setQuery(QueryBuilders.queryStringQuery("\"one two\"").field("desc")).get();
assertHitCount(searchResponse, 1); assertHitCount(searchResponse, 1);
} }
{ {
SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.queryStringQuery("\"one three\"~5").field("product.desc")).get(); SearchResponse searchResponse = client().prepareSearch("test").setTypes("product").setQuery(QueryBuilders.queryStringQuery("\"one three\"~5").field("desc")).get();
assertHitCount(searchResponse, 1); assertHitCount(searchResponse, 1);
} }
{ {
SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.queryStringQuery("\"one two\"").defaultField("customer.desc")).get(); SearchResponse searchResponse = client().prepareSearch("test").setTypes("customer").setQuery(QueryBuilders.queryStringQuery("\"one two\"").defaultField("desc")).get();
assertHitCount(searchResponse, 1); assertHitCount(searchResponse, 1);
} }
{ {
SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.queryStringQuery("\"one two\"").defaultField("customer.desc")).get(); SearchResponse searchResponse = client().prepareSearch("test").setTypes("customer").setQuery(QueryBuilders.queryStringQuery("\"one two\"").defaultField("desc")).get();
assertHitCount(searchResponse, 1); assertHitCount(searchResponse, 1);
} }
} }

View File

@ -160,8 +160,8 @@ public class SimpleQueryStringTests extends ElasticsearchIntegrationTest {
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertSearchHits(searchResponse, "1"); assertSearchHits(searchResponse, "1");
searchResponse = client().prepareSearch().setQuery( searchResponse = client().prepareSearch().setTypes("type1").setQuery(
simpleQueryStringQuery("foo bar baz").field("type1.body")).get(); simpleQueryStringQuery("foo bar baz").field("body")).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertSearchHits(searchResponse, "1"); assertSearchHits(searchResponse, "1");
@ -170,8 +170,8 @@ public class SimpleQueryStringTests extends ElasticsearchIntegrationTest {
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertSearchHits(searchResponse, "1"); assertSearchHits(searchResponse, "1");
searchResponse = client().prepareSearch().setQuery( searchResponse = client().prepareSearch().setTypes("type1").setQuery(
simpleQueryStringQuery("foo bar baz").field("type1.body.sub")).get(); simpleQueryStringQuery("foo bar baz").field("body.sub")).get();
assertHitCount(searchResponse, 1l); assertHitCount(searchResponse, 1l);
assertSearchHits(searchResponse, "1"); assertSearchHits(searchResponse, "1");
} }