Skip to content

Commit

Permalink
Mappings: Remove type prefix support from field names in queries
Browse files Browse the repository at this point in the history
This is the first part of #8872.
  • Loading branch information
rjernst committed Feb 2, 2015
1 parent 0f405e9 commit 6079d88
Show file tree
Hide file tree
Showing 32 changed files with 127 additions and 460 deletions.
37 changes: 36 additions & 1 deletion docs/reference/migration/migrate_2_0.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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" }}
]
}
}
}
---------------

Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
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
Expand Down Expand Up @@ -255,16 +254,7 @@ private Query getFieldQuerySingle(String field, String queryText, boolean quoted
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;
Expand All @@ -276,7 +266,7 @@ private Query getFieldQuerySingle(String field, String queryText, boolean quoted
if (query == null) {
query = super.getFieldQuery(currentMapper.names().indexName(), queryText, quoted);
}
return wrapSmartNameQuery(query, fieldMappers, parseContext);
return query;
}
}
return super.getFieldQuery(field, queryText, quoted);
Expand Down Expand Up @@ -387,8 +377,7 @@ private Query getRangeQuerySingle(String field, String part1, String part2, bool
}

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;
Expand Down Expand Up @@ -446,8 +435,7 @@ private Query getFuzzyQuerySingle(String field, String termStr, String minSimila
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;
Expand Down Expand Up @@ -525,21 +513,12 @@ private Query getPrefixQuerySingle(String field, String termStr) throws ParseExc
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);
Expand Down Expand Up @@ -678,7 +657,7 @@ private Query getWildcardQuerySingle(String field, String termStr) throws ParseE
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) {
Expand Down Expand Up @@ -813,21 +792,12 @@ private Query getRegexpQuerySingle(String field, String termStr) throws ParseExc
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);
Expand Down
Loading

0 comments on commit 6079d88

Please sign in to comment.