Mappings: Remove type prefix support from field names in queries
This is the first part of #8872.
This commit is contained in:
parent
0f405e9710
commit
6079d88d43
|
@ -145,5 +145,40 @@ primary shards.
|
|||
|
||||
=== 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" }}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
---------------
|
||||
|
||||
|
|
|
@ -48,7 +48,6 @@ import java.util.Collection;
|
|||
import java.util.List;
|
||||
|
||||
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
|
||||
|
@ -255,16 +254,7 @@ public class MapperQueryParser extends QueryParser {
|
|||
Query query = null;
|
||||
if (currentMapper.useTermQueryWithQueryString()) {
|
||||
try {
|
||||
if (fieldMappers.explicitTypeInNameWithDocMapper()) {
|
||||
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{fieldMappers.docMapper().type()});
|
||||
try {
|
||||
query = currentMapper.termQuery(queryText, parseContext);
|
||||
} finally {
|
||||
QueryParseContext.setTypes(previousTypes);
|
||||
}
|
||||
} else {
|
||||
query = currentMapper.termQuery(queryText, parseContext);
|
||||
}
|
||||
query = currentMapper.termQuery(queryText, parseContext);
|
||||
} catch (RuntimeException e) {
|
||||
if (settings.lenient()) {
|
||||
return null;
|
||||
|
@ -276,7 +266,7 @@ public class MapperQueryParser extends QueryParser {
|
|||
if (query == null) {
|
||||
query = super.getFieldQuery(currentMapper.names().indexName(), queryText, quoted);
|
||||
}
|
||||
return wrapSmartNameQuery(query, fieldMappers, parseContext);
|
||||
return query;
|
||||
}
|
||||
}
|
||||
return super.getFieldQuery(field, queryText, quoted);
|
||||
|
@ -387,8 +377,7 @@ public class MapperQueryParser extends QueryParser {
|
|||
}
|
||||
|
||||
try {
|
||||
Query rangeQuery = currentMapper.rangeQuery(part1, part2, startInclusive, endInclusive, parseContext);
|
||||
return wrapSmartNameQuery(rangeQuery, fieldMappers, parseContext);
|
||||
return currentMapper.rangeQuery(part1, part2, startInclusive, endInclusive, parseContext);
|
||||
} catch (RuntimeException e) {
|
||||
if (settings.lenient()) {
|
||||
return null;
|
||||
|
@ -446,8 +435,7 @@ public class MapperQueryParser extends QueryParser {
|
|||
if (currentMapper != null) {
|
||||
try {
|
||||
//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 wrapSmartNameQuery(fuzzyQuery, fieldMappers, parseContext);
|
||||
return currentMapper.fuzzyQuery(termStr, Fuzziness.build(minSimilarity), fuzzyPrefixLength, settings.fuzzyMaxExpansions(), false);
|
||||
} catch (RuntimeException e) {
|
||||
if (settings.lenient()) {
|
||||
return null;
|
||||
|
@ -525,21 +513,12 @@ public class MapperQueryParser extends QueryParser {
|
|||
if (currentMapper != null) {
|
||||
Query query = null;
|
||||
if (currentMapper.useTermQueryWithQueryString()) {
|
||||
if (fieldMappers.explicitTypeInNameWithDocMapper()) {
|
||||
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{fieldMappers.docMapper().type()});
|
||||
try {
|
||||
query = currentMapper.prefixQuery(termStr, multiTermRewriteMethod, parseContext);
|
||||
} finally {
|
||||
QueryParseContext.setTypes(previousTypes);
|
||||
}
|
||||
} else {
|
||||
query = currentMapper.prefixQuery(termStr, multiTermRewriteMethod, parseContext);
|
||||
}
|
||||
query = currentMapper.prefixQuery(termStr, multiTermRewriteMethod, parseContext);
|
||||
}
|
||||
if (query == null) {
|
||||
query = getPossiblyAnalyzedPrefixQuery(currentMapper.names().indexName(), termStr);
|
||||
}
|
||||
return wrapSmartNameQuery(query, fieldMappers, parseContext);
|
||||
return query;
|
||||
}
|
||||
}
|
||||
return getPossiblyAnalyzedPrefixQuery(field, termStr);
|
||||
|
@ -678,7 +657,7 @@ public class MapperQueryParser extends QueryParser {
|
|||
if (currentMapper != null) {
|
||||
indexedNameField = currentMapper.names().indexName();
|
||||
}
|
||||
return wrapSmartNameQuery(getPossiblyAnalyzedWildcardQuery(indexedNameField, termStr), fieldMappers, parseContext);
|
||||
return getPossiblyAnalyzedWildcardQuery(indexedNameField, termStr);
|
||||
}
|
||||
return getPossiblyAnalyzedWildcardQuery(indexedNameField, termStr);
|
||||
} catch (RuntimeException e) {
|
||||
|
@ -813,21 +792,12 @@ public class MapperQueryParser extends QueryParser {
|
|||
if (currentMapper != null) {
|
||||
Query query = null;
|
||||
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);
|
||||
} finally {
|
||||
QueryParseContext.setTypes(previousTypes);
|
||||
}
|
||||
} else {
|
||||
query = currentMapper.regexpQuery(termStr, RegExp.ALL, maxDeterminizedStates, multiTermRewriteMethod, parseContext);
|
||||
}
|
||||
query = currentMapper.regexpQuery(termStr, RegExp.ALL, maxDeterminizedStates, multiTermRewriteMethod, parseContext);
|
||||
}
|
||||
if (query == null) {
|
||||
query = super.getRegexpQuery(field, termStr);
|
||||
}
|
||||
return wrapSmartNameQuery(query, fieldMappers, parseContext);
|
||||
return query;
|
||||
}
|
||||
}
|
||||
return super.getRegexpQuery(field, termStr);
|
||||
|
|
|
@ -66,14 +66,9 @@ import org.elasticsearch.indices.TypeMissingException;
|
|||
import org.elasticsearch.percolator.PercolatorService;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
@ -91,7 +86,6 @@ public class MapperService extends AbstractIndexComponent {
|
|||
"_uid", "_id", "_type", "_all", "_analyzer", "_boost", "_parent", "_routing", "_index",
|
||||
"_size", "_timestamp", "_ttl"
|
||||
);
|
||||
|
||||
private final AnalysisService analysisService;
|
||||
private final IndexFieldDataService fieldDataService;
|
||||
|
||||
|
@ -604,20 +598,27 @@ public class MapperService extends AbstractIndexComponent {
|
|||
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
|
||||
* based on a list of types.
|
||||
*/
|
||||
public List<String> simpleMatchToIndexNames(String pattern, @Nullable String[] types) {
|
||||
if (types == null || types.length == 0) {
|
||||
return simpleMatchToIndexNames(pattern);
|
||||
}
|
||||
if (types.length == 1 && types[0].equals("_all")) {
|
||||
return simpleMatchToIndexNames(pattern);
|
||||
}
|
||||
if (!Regex.isSimpleMatchPattern(pattern)) {
|
||||
if (Regex.isSimpleMatchPattern(pattern) == false) {
|
||||
// no wildcards
|
||||
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();
|
||||
for (String type : types) {
|
||||
DocumentMapper possibleDocMapper = mappers.get(type);
|
||||
|
@ -630,35 +631,13 @@ public class MapperService extends AbstractIndexComponent {
|
|||
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) {
|
||||
if (types == null || types.length == 0) {
|
||||
return smartNameObjectMapper(smartName);
|
||||
}
|
||||
if (types.length == 1 && types[0].equals("_all")) {
|
||||
return smartNameObjectMapper(smartName);
|
||||
if (types == null || types.length == 0 || types.length == 1 && types[0].equals("_all")) {
|
||||
ObjectMappers mappers = objectMapper(smartName);
|
||||
if (mappers != null) {
|
||||
return new SmartNameObjectMapper(mappers.mapper(), guessDocMapper(smartName));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
for (String type : types) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -772,18 +702,6 @@ public class MapperService extends AbstractIndexComponent {
|
|||
* Same as {@link #smartName(String)}, except it returns just the field mappers.
|
||||
*/
|
||||
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);
|
||||
if (mappers != null) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -844,18 +747,6 @@ public class MapperService extends AbstractIndexComponent {
|
|||
* <p>If nothing is found, returns null.
|
||||
*/
|
||||
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);
|
||||
if (fieldMappers != null) {
|
||||
return new SmartNameFieldMappers(this, fieldMappers, null, false);
|
||||
|
@ -942,7 +833,7 @@ public class MapperService extends AbstractIndexComponent {
|
|||
public static boolean isMetadataField(String fieldName) {
|
||||
return META_FIELDS.contains(fieldName);
|
||||
}
|
||||
|
||||
|
||||
public static class SmartNameObjectMapper {
|
||||
private final ObjectMapper mapper;
|
||||
private final DocumentMapper docMapper;
|
||||
|
@ -973,13 +864,11 @@ public class MapperService extends AbstractIndexComponent {
|
|||
private final MapperService mapperService;
|
||||
private final FieldMappers fieldMappers;
|
||||
private final DocumentMapper docMapper;
|
||||
private final boolean explicitTypeInName;
|
||||
|
||||
public SmartNameFieldMappers(MapperService mapperService, FieldMappers fieldMappers, @Nullable DocumentMapper docMapper, boolean explicitTypeInName) {
|
||||
this.mapperService = mapperService;
|
||||
this.fieldMappers = fieldMappers;
|
||||
this.docMapper = docMapper;
|
||||
this.explicitTypeInName = explicitTypeInName;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1019,17 +908,6 @@ public class MapperService extends AbstractIndexComponent {
|
|||
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.
|
||||
*/
|
||||
|
@ -1065,14 +943,6 @@ public class MapperService extends AbstractIndexComponent {
|
|||
|
||||
@Override
|
||||
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);
|
||||
if (mappers != null && mappers.mapper() != null && mappers.mapper().searchAnalyzer() != null) {
|
||||
return mappers.mapper().searchAnalyzer();
|
||||
|
@ -1097,14 +967,6 @@ public class MapperService extends AbstractIndexComponent {
|
|||
|
||||
@Override
|
||||
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);
|
||||
if (mappers != null && mappers.mapper() != null && mappers.mapper().searchQuoteAnalyzer() != null) {
|
||||
return mappers.mapper().searchQuoteAnalyzer();
|
||||
|
|
|
@ -36,8 +36,6 @@ import org.elasticsearch.index.mapper.MapperService;
|
|||
|
||||
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.setHighFreqMinimumNumberShouldMatch(highFreqMinimumShouldMatch);
|
||||
return wrapSmartNameQuery(query, smartNameFieldMappers, parseContext);
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,8 +35,6 @@ import org.elasticsearch.index.mapper.internal.FieldNamesFieldMapper;
|
|||
import java.io.IOException;
|
||||
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...
|
||||
Filter filter = parseContext.cacheFilter(boolFilter, new HashedBytesRef("$exists$" + fieldPattern), parseContext.autoFilterCachePolicy());
|
||||
|
||||
filter = wrapSmartNameFilter(filter, nonNullFieldMappers, parseContext);
|
||||
if (filterName != null) {
|
||||
parseContext.addNamedFilter(filterName, filter);
|
||||
}
|
||||
|
|
|
@ -33,8 +33,6 @@ import org.elasticsearch.index.mapper.MapperService;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameQuery;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* {
|
||||
|
@ -154,10 +152,9 @@ public class FuzzyLikeThisFieldQueryParser implements QueryParser {
|
|||
}
|
||||
assert token == XContentParser.Token.END_OBJECT;
|
||||
|
||||
Query query = wrapSmartNameQuery(fuzzyLikeThisQuery, smartNameFieldMappers, parseContext);
|
||||
if (queryName != null) {
|
||||
parseContext.addNamedQuery(queryName, query);
|
||||
parseContext.addNamedQuery(queryName, fuzzyLikeThisQuery);
|
||||
}
|
||||
return query;
|
||||
return fuzzyLikeThisQuery;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,8 +32,6 @@ import org.elasticsearch.index.query.support.QueryParsers;
|
|||
|
||||
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 = wrapSmartNameQuery(query, smartNameFieldMappers, parseContext);
|
||||
if (queryName != null) {
|
||||
parseContext.addNamedQuery(queryName, query);
|
||||
}
|
||||
|
|
|
@ -36,8 +36,6 @@ import org.elasticsearch.index.search.geo.IndexedGeoBoundingBoxFilter;
|
|||
|
||||
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) {
|
||||
filter = parseContext.cacheFilter(filter, cacheKey, cache);
|
||||
}
|
||||
filter = wrapSmartNameFilter(filter, smartMappers, parseContext);
|
||||
if (filterName != null) {
|
||||
parseContext.addNamedFilter(filterName, filter);
|
||||
}
|
||||
|
|
|
@ -37,8 +37,6 @@ import org.elasticsearch.index.search.geo.GeoDistanceFilter;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameFilter;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* {
|
||||
|
@ -171,7 +169,6 @@ public class GeoDistanceFilterParser implements FilterParser {
|
|||
if (cache != null) {
|
||||
filter = parseContext.cacheFilter(filter, cacheKey, cache);
|
||||
}
|
||||
filter = wrapSmartNameFilter(filter, smartMappers, parseContext);
|
||||
if (filterName != null) {
|
||||
parseContext.addNamedFilter(filterName, filter);
|
||||
}
|
||||
|
|
|
@ -37,8 +37,6 @@ import org.elasticsearch.index.search.geo.GeoDistanceRangeFilter;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameFilter;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* {
|
||||
|
@ -211,7 +209,6 @@ public class GeoDistanceRangeFilterParser implements FilterParser {
|
|||
if (cache != null) {
|
||||
filter = parseContext.cacheFilter(filter, cacheKey, cache);
|
||||
}
|
||||
filter = wrapSmartNameFilter(filter, smartMappers, parseContext);
|
||||
if (filterName != null) {
|
||||
parseContext.addNamedFilter(filterName, filter);
|
||||
}
|
||||
|
|
|
@ -38,8 +38,6 @@ import org.elasticsearch.index.search.geo.GeoPolygonFilter;
|
|||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameFilter;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* {
|
||||
|
@ -157,7 +155,6 @@ public class GeoPolygonFilterParser implements FilterParser {
|
|||
if (cache != null) {
|
||||
filter = parseContext.cacheFilter(filter, cacheKey, cache);
|
||||
}
|
||||
filter = wrapSmartNameFilter(filter, smartMappers, parseContext);
|
||||
if (filterName != null) {
|
||||
parseContext.addNamedFilter(filterName, filter);
|
||||
}
|
||||
|
|
|
@ -40,8 +40,6 @@ import org.elasticsearch.index.search.shape.ShapeFetchService;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameFilter;
|
||||
|
||||
/**
|
||||
* {@link FilterParser} for filtering Documents based on {@link Shape}s.
|
||||
* <p/>
|
||||
|
@ -199,8 +197,6 @@ public class GeoShapeFilterParser implements FilterParser {
|
|||
filter = parseContext.cacheFilter(filter, cacheKey, cache);
|
||||
}
|
||||
|
||||
filter = wrapSmartNameFilter(filter, smartNameFieldMappers, parseContext);
|
||||
|
||||
if (filterName != null) {
|
||||
parseContext.addNamedFilter(filterName, filter);
|
||||
}
|
||||
|
|
|
@ -36,8 +36,6 @@ import org.elasticsearch.index.mapper.internal.FieldNamesFieldMapper;
|
|||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameFilter;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -185,7 +183,6 @@ public class MissingFilterParser implements FilterParser {
|
|||
return null;
|
||||
}
|
||||
|
||||
filter = wrapSmartNameFilter(filter, nonNullFieldMappers, parseContext);
|
||||
if (filterName != null) {
|
||||
parseContext.addNamedFilter(filterName, existenceFilter);
|
||||
}
|
||||
|
|
|
@ -31,8 +31,6 @@ import org.elasticsearch.index.mapper.MapperService;
|
|||
|
||||
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);
|
||||
if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) {
|
||||
if (smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
|
||||
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{smartNameFieldMappers.docMapper().type()});
|
||||
try {
|
||||
filter = smartNameFieldMappers.mapper().prefixFilter(value, parseContext);
|
||||
} finally {
|
||||
QueryParseContext.setTypes(previousTypes);
|
||||
}
|
||||
} else {
|
||||
filter = smartNameFieldMappers.mapper().prefixFilter(value, parseContext);
|
||||
}
|
||||
filter = smartNameFieldMappers.mapper().prefixFilter(value, parseContext);
|
||||
}
|
||||
if (filter == null) {
|
||||
filter = new PrefixFilter(new Term(fieldName, BytesRefs.toBytesRef(value)));
|
||||
|
@ -104,8 +93,6 @@ public class PrefixFilterParser implements FilterParser {
|
|||
if (cache != null) {
|
||||
filter = parseContext.cacheFilter(filter, cacheKey, cache);
|
||||
}
|
||||
|
||||
filter = wrapSmartNameFilter(filter, smartNameFieldMappers, parseContext);
|
||||
if (filterName != null) {
|
||||
parseContext.addNamedFilter(filterName, filter);
|
||||
}
|
||||
|
|
|
@ -31,8 +31,6 @@ import org.elasticsearch.index.query.support.QueryParsers;
|
|||
|
||||
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;
|
||||
MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
|
||||
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);
|
||||
} finally {
|
||||
QueryParseContext.setTypes(previousTypes);
|
||||
}
|
||||
} else {
|
||||
query = smartNameFieldMappers.mapper().prefixQuery(value, method, parseContext);
|
||||
}
|
||||
query = smartNameFieldMappers.mapper().prefixQuery(value, method, parseContext);
|
||||
}
|
||||
if (query == null) {
|
||||
PrefixQuery prefixQuery = new PrefixQuery(new Term(fieldName, BytesRefs.toBytesRef(value)));
|
||||
|
@ -119,7 +108,6 @@ public class PrefixQueryParser implements QueryParser {
|
|||
query = prefixQuery;
|
||||
}
|
||||
query.setBoost(boost);
|
||||
query = wrapSmartNameQuery(query, smartNameFieldMappers, parseContext);
|
||||
if (queryName != null) {
|
||||
parseContext.addNamedQuery(queryName, query);
|
||||
}
|
||||
|
|
|
@ -36,8 +36,6 @@ import org.joda.time.DateTimeZone;
|
|||
|
||||
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 = wrapSmartNameFilter(filter, smartNameFieldMappers, parseContext);
|
||||
if (filterName != null) {
|
||||
parseContext.addNamedFilter(filterName, filter);
|
||||
}
|
||||
|
|
|
@ -33,8 +33,6 @@ import org.joda.time.DateTimeZone;
|
|||
|
||||
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.setBoost(boost);
|
||||
query = wrapSmartNameQuery(query, smartNameFieldMappers, parseContext);
|
||||
if (queryName != null) {
|
||||
parseContext.addNamedQuery(queryName, query);
|
||||
}
|
||||
|
|
|
@ -32,8 +32,6 @@ import org.elasticsearch.index.mapper.MapperService;
|
|||
|
||||
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);
|
||||
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);
|
||||
} finally {
|
||||
QueryParseContext.setTypes(previousTypes);
|
||||
}
|
||||
} else {
|
||||
filter = smartNameFieldMappers.mapper().regexpFilter(value, flagsValue, maxDeterminizedStates, parseContext);
|
||||
}
|
||||
filter = smartNameFieldMappers.mapper().regexpFilter(value, flagsValue, maxDeterminizedStates, parseContext);
|
||||
}
|
||||
if (filter == null) {
|
||||
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 = wrapSmartNameFilter(filter, smartNameFieldMappers, parseContext);
|
||||
if (filterName != null) {
|
||||
parseContext.addNamedFilter(filterName, filter);
|
||||
}
|
||||
|
|
|
@ -33,8 +33,6 @@ import org.elasticsearch.index.query.support.QueryParsers;
|
|||
|
||||
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;
|
||||
MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
|
||||
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);
|
||||
} finally {
|
||||
QueryParseContext.setTypes(previousTypes);
|
||||
}
|
||||
} else {
|
||||
query = smartNameFieldMappers.mapper().regexpQuery(value, flagsValue, maxDeterminizedStates, method, parseContext);
|
||||
}
|
||||
query = smartNameFieldMappers.mapper().regexpQuery(value, flagsValue, maxDeterminizedStates, method, parseContext);
|
||||
}
|
||||
if (query == null) {
|
||||
RegexpQuery regexpQuery = new RegexpQuery(new Term(fieldName, BytesRefs.toBytesRef(value)), flagsValue, maxDeterminizedStates);
|
||||
|
@ -131,7 +120,6 @@ public class RegexpQueryParser implements QueryParser {
|
|||
query = regexpQuery;
|
||||
}
|
||||
query.setBoost(boost);
|
||||
query = wrapSmartNameQuery(query, smartNameFieldMappers, parseContext);
|
||||
if (queryName != null) {
|
||||
parseContext.addNamedQuery(queryName, query);
|
||||
}
|
||||
|
|
|
@ -31,8 +31,6 @@ import org.elasticsearch.index.mapper.MapperService;
|
|||
|
||||
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;
|
||||
MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
|
||||
if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) {
|
||||
if (smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
|
||||
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{smartNameFieldMappers.docMapper().type()});
|
||||
try {
|
||||
filter = smartNameFieldMappers.mapper().termFilter(value, parseContext);
|
||||
} finally {
|
||||
QueryParseContext.setTypes(previousTypes);
|
||||
}
|
||||
} else {
|
||||
filter = smartNameFieldMappers.mapper().termFilter(value, parseContext);
|
||||
}
|
||||
filter = smartNameFieldMappers.mapper().termFilter(value, parseContext);
|
||||
}
|
||||
if (filter == null) {
|
||||
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 = wrapSmartNameFilter(filter, smartNameFieldMappers, parseContext);
|
||||
if (filterName != null) {
|
||||
parseContext.addNamedFilter(filterName, filter);
|
||||
}
|
||||
|
|
|
@ -29,8 +29,6 @@ import org.elasticsearch.index.mapper.MapperService;
|
|||
|
||||
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;
|
||||
MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
|
||||
if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) {
|
||||
if (smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
|
||||
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{smartNameFieldMappers.docMapper().type()});
|
||||
try {
|
||||
query = smartNameFieldMappers.mapper().termQuery(value, parseContext);
|
||||
} finally {
|
||||
QueryParseContext.setTypes(previousTypes);
|
||||
}
|
||||
} else {
|
||||
query = smartNameFieldMappers.mapper().termQuery(value, parseContext);
|
||||
}
|
||||
query = smartNameFieldMappers.mapper().termQuery(value, parseContext);
|
||||
}
|
||||
if (query == null) {
|
||||
query = new TermQuery(new Term(fieldName, BytesRefs.toBytesRef(value)));
|
||||
}
|
||||
query.setBoost(boost);
|
||||
query = wrapSmartNameQuery(query, smartNameFieldMappers, parseContext);
|
||||
if (queryName != null) {
|
||||
parseContext.addNamedQuery(queryName, query);
|
||||
}
|
||||
|
|
|
@ -47,8 +47,6 @@ import org.elasticsearch.indices.cache.filter.terms.TermsLookup;
|
|||
import java.io.IOException;
|
||||
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;
|
||||
smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
|
||||
String[] previousTypes = null;
|
||||
if (smartNameFieldMappers != null) {
|
||||
if (smartNameFieldMappers.hasMapper()) {
|
||||
fieldMapper = smartNameFieldMappers.mapper();
|
||||
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) {
|
||||
|
@ -192,8 +185,7 @@ public class TermsFilterParser implements FilterParser {
|
|||
if (terms.isEmpty()) {
|
||||
return Queries.MATCH_NO_FILTER;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
Filter filter;
|
||||
if (EXECUTION_VALUE_PLAIN.equals(execution)) {
|
||||
if (fieldMapper != null) {
|
||||
|
@ -211,7 +203,7 @@ public class TermsFilterParser implements FilterParser {
|
|||
if (fieldMapper == null) {
|
||||
return Queries.MATCH_NO_FILTER;
|
||||
}
|
||||
|
||||
|
||||
filter = fieldMapper.fieldDataTermsFilter(terms, parseContext);
|
||||
} else if (EXECUTION_VALUE_BOOL.equals(execution)) {
|
||||
XBooleanFilter boolFiler = new XBooleanFilter();
|
||||
|
@ -288,20 +280,14 @@ public class TermsFilterParser implements FilterParser {
|
|||
} else {
|
||||
throw new QueryParsingException(parseContext.index(), "terms filter execution value [" + execution + "] not supported");
|
||||
}
|
||||
|
||||
|
||||
if (cache != null) {
|
||||
filter = parseContext.cacheFilter(filter, cacheKey, cache);
|
||||
}
|
||||
|
||||
filter = wrapSmartNameFilter(filter, smartNameFieldMappers, parseContext);
|
||||
|
||||
if (filterName != null) {
|
||||
parseContext.addNamedFilter(filterName, filter);
|
||||
}
|
||||
return filter;
|
||||
} finally {
|
||||
if (smartNameFieldMappers != null && smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
|
||||
QueryParseContext.setTypes(previousTypes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ import java.util.List;
|
|||
|
||||
import static com.google.common.collect.Lists.newArrayList;
|
||||
import static org.elasticsearch.common.lucene.search.Queries.fixNegativeQueryIfNeeded;
|
||||
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameQuery;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
|
@ -114,32 +113,24 @@ public class TermsQueryParser implements QueryParser {
|
|||
String[] previousTypes = null;
|
||||
if (smartNameFieldMappers != null && smartNameFieldMappers.hasMapper()) {
|
||||
mapper = smartNameFieldMappers.mapper();
|
||||
if (smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
|
||||
previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{smartNameFieldMappers.docMapper().type()});
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
BooleanQuery booleanQuery = new BooleanQuery(disableCoord);
|
||||
for (Object value : values) {
|
||||
if (mapper != null) {
|
||||
booleanQuery.add(new BooleanClause(mapper.termQuery(value, parseContext), BooleanClause.Occur.SHOULD));
|
||||
} else {
|
||||
booleanQuery.add(new TermQuery(new Term(fieldName, BytesRefs.toString(value))), BooleanClause.Occur.SHOULD);
|
||||
}
|
||||
}
|
||||
booleanQuery.setBoost(boost);
|
||||
Queries.applyMinimumShouldMatch(booleanQuery, minimumShouldMatch);
|
||||
Query query = wrapSmartNameQuery(fixNegativeQueryIfNeeded(booleanQuery), smartNameFieldMappers, parseContext);
|
||||
if (queryName != null) {
|
||||
parseContext.addNamedQuery(queryName, query);
|
||||
}
|
||||
return query;
|
||||
} finally {
|
||||
if (smartNameFieldMappers != null && smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
|
||||
QueryParseContext.setTypes(previousTypes);
|
||||
|
||||
BooleanQuery booleanQuery = new BooleanQuery(disableCoord);
|
||||
for (Object value : values) {
|
||||
if (mapper != null) {
|
||||
booleanQuery.add(new BooleanClause(mapper.termQuery(value, parseContext), BooleanClause.Occur.SHOULD));
|
||||
} else {
|
||||
booleanQuery.add(new TermQuery(new Term(fieldName, BytesRefs.toString(value))), BooleanClause.Occur.SHOULD);
|
||||
}
|
||||
}
|
||||
booleanQuery.setBoost(boost);
|
||||
Queries.applyMinimumShouldMatch(booleanQuery, minimumShouldMatch);
|
||||
Query query = fixNegativeQueryIfNeeded(booleanQuery);
|
||||
if (queryName != null) {
|
||||
parseContext.addNamedQuery(queryName, query);
|
||||
}
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,8 +30,6 @@ import org.elasticsearch.index.query.support.QueryParsers;
|
|||
|
||||
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);
|
||||
wildcardQuery.setRewriteMethod(QueryParsers.parseRewriteMethod(rewriteMethod));
|
||||
wildcardQuery.setBoost(boost);
|
||||
Query query = wrapSmartNameQuery(wildcardQuery, smartNameFieldMappers, parseContext);
|
||||
if (queryName != null) {
|
||||
parseContext.addNamedQuery(queryName, query);
|
||||
parseContext.addNamedQuery(queryName, wildcardQuery);
|
||||
}
|
||||
return query;
|
||||
return wildcardQuery;
|
||||
}
|
||||
}
|
|
@ -92,31 +92,5 @@ public final class QueryParsers {
|
|||
}
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,8 +39,6 @@ import org.elasticsearch.index.query.support.QueryParsers;
|
|||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameQuery;
|
||||
|
||||
public class MatchQuery {
|
||||
|
||||
public static enum Type {
|
||||
|
@ -176,28 +174,15 @@ public class MatchQuery {
|
|||
}
|
||||
|
||||
if (mapper != null && mapper.useTermQueryWithQueryString() && !forceAnalyzeQueryString()) {
|
||||
if (smartNameFieldMappers.explicitTypeInNameWithDocMapper()) {
|
||||
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{smartNameFieldMappers.docMapper().type()});
|
||||
try {
|
||||
return wrapSmartNameQuery(mapper.termQuery(value, parseContext), smartNameFieldMappers, 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) {
|
||||
if (lenient) {
|
||||
return null;
|
||||
}
|
||||
throw e;
|
||||
try {
|
||||
return mapper.termQuery(value, parseContext);
|
||||
} catch (RuntimeException e) {
|
||||
if (lenient) {
|
||||
return null;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
Analyzer analyzer = getAnalyzer(mapper, smartNameFieldMappers);
|
||||
MatchQueryBuilder builder = new MatchQueryBuilder(analyzer, mapper);
|
||||
|
@ -225,7 +210,7 @@ public class MatchQuery {
|
|||
if (query == null) {
|
||||
return zeroTermsQuery();
|
||||
} else {
|
||||
return wrapSmartNameQuery(query, smartNameFieldMappers, parseContext);
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -135,15 +135,7 @@ public class HighlightPhase extends AbstractComponent implements FetchSubPhase {
|
|||
|
||||
private FieldMapper<?> getMapperForField(String fieldName, SearchContext searchContext, HitContext hitContext) {
|
||||
DocumentMapper documentMapper = searchContext.mapperService().documentMapper(hitContext.hit().type());
|
||||
FieldMapper<?> mapper = documentMapper.mappers().smartNameFieldMapper(fieldName);
|
||||
if (mapper == null) {
|
||||
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;
|
||||
// TODO: no need to lookup the doc mapper with unambiguous field names? just look at the mapper service
|
||||
return documentMapper.mappers().smartNameFieldMapper(fieldName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -825,14 +825,11 @@ public class CountQueryTests extends ElasticsearchIntegrationTest {
|
|||
CountResponse response = client().prepareCount("test")
|
||||
.setQuery(QueryBuilders.spanOrQuery().clause(QueryBuilders.spanTermQuery("description", "bar"))).get();
|
||||
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(
|
||||
QueryBuilders.spanNearQuery()
|
||||
.clause(QueryBuilders.spanTermQuery("description", "foo"))
|
||||
.clause(QueryBuilders.spanTermQuery("test.description", "other"))
|
||||
.clause(QueryBuilders.spanTermQuery("description", "other"))
|
||||
.slop(3)).get();
|
||||
assertHitCount(response, 3l);
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public class SimpleNestedTests extends ElasticsearchIntegrationTest {
|
|||
// check on no data, see it works
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setQuery(termQuery("_all", "n_value1_1")).execute().actionGet();
|
||||
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));
|
||||
|
||||
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
|
||||
searchResponse = client().prepareSearch("test").setQuery(termQuery("_all", "n_value1_1")).execute().actionGet();
|
||||
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));
|
||||
|
||||
// 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();
|
||||
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));
|
||||
|
||||
// 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);
|
||||
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);
|
||||
assertThat(searchResponse.getHits().totalHits(), equalTo(1l));
|
||||
|
||||
|
@ -130,19 +130,19 @@ public class SimpleNestedTests extends ElasticsearchIntegrationTest {
|
|||
assertDocumentCount("test", 6);
|
||||
|
||||
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);
|
||||
assertThat(searchResponse.getHits().totalHits(), equalTo(1l));
|
||||
|
||||
// filter
|
||||
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);
|
||||
assertThat(searchResponse.getHits().totalHits(), equalTo(1l));
|
||||
|
||||
// check with type prefix
|
||||
searchResponse = client().prepareSearch("test").setQuery(nestedQuery("type1.nested1",
|
||||
boolQuery().must(termQuery("nested1.n_field1", "n_value1_1")).must(termQuery("nested1.n_field2", "n_value2_1")))).execute().actionGet();
|
||||
searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1",
|
||||
boolQuery().must(termQuery("n_field1", "n_value1_1")).must(termQuery("n_field2", "n_value2_1")))).execute().actionGet();
|
||||
assertNoFailures(searchResponse);
|
||||
assertThat(searchResponse.getHits().totalHits(), equalTo(1l));
|
||||
|
||||
|
@ -154,11 +154,11 @@ public class SimpleNestedTests extends ElasticsearchIntegrationTest {
|
|||
flush();
|
||||
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);
|
||||
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);
|
||||
assertThat(searchResponse.getHits().totalHits(), equalTo(1l));
|
||||
}
|
||||
|
|
|
@ -250,15 +250,6 @@ public class SimpleChildQuerySearchTests extends ElasticsearchIntegrationTest {
|
|||
assertThat(searchResponse.getHits().getAt(0).field("_parent").value().toString(), equalTo("p1"));
|
||||
|
||||
// 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();
|
||||
assertNoFailures(searchResponse);
|
||||
assertThat(searchResponse.getHits().totalHits(), equalTo(2l));
|
||||
|
|
|
@ -1492,14 +1492,10 @@ public class SearchQueryTests extends ElasticsearchIntegrationTest {
|
|||
.setQuery(spanOrQuery().clause(spanTermQuery("description", "bar"))).get();
|
||||
assertHitCount(searchResponse, 1l);
|
||||
|
||||
searchResponse = client().prepareSearch("test")
|
||||
.setQuery(spanOrQuery().clause(spanTermQuery("test.description", "bar"))).get();
|
||||
assertHitCount(searchResponse, 1l);
|
||||
|
||||
searchResponse = client().prepareSearch("test").setQuery(
|
||||
spanNearQuery()
|
||||
.clause(spanTermQuery("description", "foo"))
|
||||
.clause(spanTermQuery("test.description", "other"))
|
||||
.clause(spanTermQuery("description", "other"))
|
||||
.slop(3)).get();
|
||||
assertHitCount(searchResponse, 3l);
|
||||
}
|
||||
|
@ -2097,19 +2093,19 @@ public class SearchQueryTests extends ElasticsearchIntegrationTest {
|
|||
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);
|
||||
}
|
||||
{
|
||||
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);
|
||||
}
|
||||
{
|
||||
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);
|
||||
}
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,8 +160,8 @@ public class SimpleQueryStringTests extends ElasticsearchIntegrationTest {
|
|||
assertHitCount(searchResponse, 1l);
|
||||
assertSearchHits(searchResponse, "1");
|
||||
|
||||
searchResponse = client().prepareSearch().setQuery(
|
||||
simpleQueryStringQuery("foo bar baz").field("type1.body")).get();
|
||||
searchResponse = client().prepareSearch().setTypes("type1").setQuery(
|
||||
simpleQueryStringQuery("foo bar baz").field("body")).get();
|
||||
assertHitCount(searchResponse, 1l);
|
||||
assertSearchHits(searchResponse, "1");
|
||||
|
||||
|
@ -170,8 +170,8 @@ public class SimpleQueryStringTests extends ElasticsearchIntegrationTest {
|
|||
assertHitCount(searchResponse, 1l);
|
||||
assertSearchHits(searchResponse, "1");
|
||||
|
||||
searchResponse = client().prepareSearch().setQuery(
|
||||
simpleQueryStringQuery("foo bar baz").field("type1.body.sub")).get();
|
||||
searchResponse = client().prepareSearch().setTypes("type1").setQuery(
|
||||
simpleQueryStringQuery("foo bar baz").field("body.sub")).get();
|
||||
assertHitCount(searchResponse, 1l);
|
||||
assertSearchHits(searchResponse, "1");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue