Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.index.mapper.TypeFieldMapper;
import org.elasticsearch.rest.action.document.RestGetAction;
import org.elasticsearch.rest.action.document.RestUpdateAction;
import org.elasticsearch.rest.action.search.RestExplainAction;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.CheckedFunction;
Expand All @@ -37,6 +33,9 @@
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.rest.action.document.RestGetAction;
import org.elasticsearch.rest.action.document.RestUpdateAction;
import org.elasticsearch.rest.action.search.RestExplainAction;
import org.elasticsearch.test.NotEqualMessageBuilder;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.yaml.ObjectPath;
Expand Down Expand Up @@ -574,8 +573,7 @@ void assertAllSearchWorks(int count) throws IOException {

Request explainRequest = new Request("GET", "/" + index + "/" + type + "/" + id + "/_explain");
explainRequest.setJsonEntity("{ \"query\": { \"match_all\" : {} }}");
explainRequest.setOptions(
expectWarnings(RestExplainAction.TYPES_DEPRECATION_MESSAGE, TypeFieldMapper.TypeFieldType.TYPES_DEPRECATION_MESSAGE));
explainRequest.setOptions(expectWarnings(RestExplainAction.TYPES_DEPRECATION_MESSAGE));
String explanation = toStr(client().performRequest(explainRequest));
assertFalse("Could not find payload boost in explanation\n" + explanation, explanation.contains("payloadBoost"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.elasticsearch.index.mapper;

import org.apache.logging.log4j.LogManager;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.SortedSetDocValuesField;
import org.apache.lucene.index.IndexOptions;
Expand All @@ -36,7 +35,6 @@
import org.apache.lucene.search.TermInSetQuery;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.lucene.search.Queries;
import org.elasticsearch.common.xcontent.XContentBuilder;
Expand Down Expand Up @@ -92,10 +90,6 @@ public MetadataFieldMapper getDefault(MappedFieldType fieldType, ParserContext c

public static final class TypeFieldType extends StringFieldType {

private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(TypeFieldType.class));
public static final String TYPES_DEPRECATION_MESSAGE =
"[types removal] Referring to types within search queries is deprecated, filter on a field instead.";

TypeFieldType() {
}

Expand Down Expand Up @@ -126,7 +120,6 @@ public boolean isSearchable() {

@Override
public Query existsQuery(QueryShardContext context) {
deprecationLogger.deprecatedAndMaybeLog("exists_query_with_type_field", TYPES_DEPRECATION_MESSAGE);
return new MatchAllDocsQuery();
}

Expand All @@ -137,7 +130,6 @@ public Query termQuery(Object value, QueryShardContext context) {

@Override
public Query termsQuery(List<?> values, QueryShardContext context) {
deprecationLogger.deprecatedAndMaybeLog("term_query_with_type_field", TYPES_DEPRECATION_MESSAGE);
DocumentMapper mapper = context.getMapperService().documentMapper();
if (mapper == null) {
return new MatchNoDocsQuery("No types");
Expand All @@ -159,7 +151,6 @@ public Query termsQuery(List<?> values, QueryShardContext context) {

@Override
public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, QueryShardContext context) {
deprecationLogger.deprecatedAndMaybeLog("range_query_with_type_field", TYPES_DEPRECATION_MESSAGE);
Query result = new MatchAllDocsQuery();
String type = context.getMapperService().documentMapper().type();
if (type != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.index.query;

import org.apache.logging.log4j.LogManager;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.Query;
Expand All @@ -32,6 +33,7 @@
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.lucene.search.Queries;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentParser;
Expand All @@ -47,6 +49,7 @@
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.ObjectMapper;
import org.elasticsearch.index.mapper.TextFieldMapper;
import org.elasticsearch.index.mapper.TypeFieldMapper;
import org.elasticsearch.index.query.support.NestedScope;
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.script.ScriptService;
Expand All @@ -70,6 +73,10 @@
* Context object used to create lucene queries on the shard level.
*/
public class QueryShardContext extends QueryRewriteContext {
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(
LogManager.getLogger(QueryShardContext.class));
static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Using the _type field " +
"in queries is deprecated, prefer to filter on a field instead.";

private final ScriptService scriptService;
private final IndexSettings indexSettings;
Expand Down Expand Up @@ -185,6 +192,9 @@ public Collection<String> simpleMatchToIndexNames(String pattern) {
}

public MappedFieldType fieldMapper(String name) {
if (name.equals(TypeFieldMapper.NAME)) {
deprecationLogger.deprecatedAndMaybeLog("query_with_types", TYPES_DEPRECATION_MESSAGE);
}
return failIfFieldMappingNotFound(name, mapperService.fullName(name));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.TypeFieldMapper;

import java.io.IOException;
import java.util.Objects;
Expand All @@ -41,7 +40,10 @@ public class TypeQueryBuilder extends AbstractQueryBuilder<TypeQueryBuilder> {
public static final String NAME = "type";

private static final ParseField VALUE_FIELD = new ParseField("value");
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(TypeQueryBuilder.class));
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(
LogManager.getLogger(TypeQueryBuilder.class));
static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Type queries are deprecated, " +
"prefer to filter on a field instead.";

private final String type;

Expand Down Expand Up @@ -128,7 +130,7 @@ public String getWriteableName() {

@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
deprecationLogger.deprecatedAndMaybeLog("type_query", TypeFieldMapper.TypeFieldType.TYPES_DEPRECATION_MESSAGE);
deprecationLogger.deprecatedAndMaybeLog("type_query", TYPES_DEPRECATION_MESSAGE);
//LUCENE 4 UPGRADE document mapper should use bytesref as well?
DocumentMapper documentMapper = context.getMapperService().documentMapper(type);
if (documentMapper == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
*/
package org.elasticsearch.index.mapper;

import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.document.StringField;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.Query;
Expand All @@ -36,8 +31,6 @@
import org.elasticsearch.test.VersionUtils;
import org.mockito.Mockito;

import java.io.IOException;

public class TypeFieldTypeTests extends FieldTypeTestCase {
@Override
protected MappedFieldType createDefaultFieldType() {
Expand Down Expand Up @@ -81,36 +74,5 @@ public void testTermsQuery() throws Exception {
Mockito.when(mapperService.documentMapper()).thenReturn(mapper);
query = ft.termQuery("my_type", context);
assertEquals(new MatchNoDocsQuery(), query);
assertWarnings(TypeFieldMapper.TypeFieldType.TYPES_DEPRECATION_MESSAGE);
}

public void testExistsQuery() {
QueryShardContext context = Mockito.mock(QueryShardContext.class);
TypeFieldMapper.TypeFieldType ft = new TypeFieldMapper.TypeFieldType();
ft.setName(TypeFieldMapper.NAME);
ft.existsQuery(context);
assertWarnings(TypeFieldMapper.TypeFieldType.TYPES_DEPRECATION_MESSAGE);
}

public void testRangeQuery() {
QueryShardContext context = Mockito.mock(QueryShardContext.class);
MapperService mapperService = Mockito.mock(MapperService.class);
DocumentMapper mapper = Mockito.mock(DocumentMapper.class);
Mockito.when(context.getMapperService()).thenReturn(mapperService);
Mockito.when(mapperService.documentMapper()).thenReturn(mapper);
Mockito.when(mapper.type()).thenReturn("my_type");

TypeFieldMapper.TypeFieldType ft = new TypeFieldMapper.TypeFieldType();
ft.setName(TypeFieldMapper.NAME);
ft.rangeQuery("type1", "type2", true, true, context);
assertWarnings(TypeFieldMapper.TypeFieldType.TYPES_DEPRECATION_MESSAGE);
}

static DirectoryReader openReaderWithNewType(String type, IndexWriter writer) throws IOException {
Document doc = new Document();
StringField typeField = new StringField(TypeFieldMapper.NAME, type, Store.NO);
doc.add(typeField);
writer.addDocument(doc);
return DirectoryReader.open(writer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -592,4 +592,11 @@ public boolean convertNowRangeToMatchAll() {
rewritten = query.rewrite(queryShardContext);
assertThat(rewritten, instanceOf(MatchAllQueryBuilder.class));
}

public void testTypeField() throws IOException {
RangeQueryBuilder builder = QueryBuilders.rangeQuery("_type")
.from("value1");
builder.doToQuery(createShardContext());
assertWarnings(QueryShardContext.TYPES_DEPRECATION_MESSAGE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,10 @@ public void testParseFailsWithMultipleFields() throws IOException {
e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
assertEquals("[term] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
}

public void testTypeField() throws IOException {
TermQueryBuilder builder = QueryBuilders.termQuery("_type", "value1");
builder.doToQuery(createShardContext());
assertWarnings(QueryShardContext.TYPES_DEPRECATION_MESSAGE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -310,5 +310,11 @@ public void testConversion() {
assertEquals(Arrays.asList(5, 42d), TermsQueryBuilder.convert(list));
assertEquals(Arrays.asList(5, 42d), TermsQueryBuilder.convertBack(TermsQueryBuilder.convert(list)));
}

public void testTypeField() throws IOException {
TermsQueryBuilder builder = QueryBuilders.termsQuery("_type", "value1", "value2");
builder.doToQuery(createShardContext());
assertWarnings(QueryShardContext.TYPES_DEPRECATION_MESSAGE);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ public void testFromJson() throws IOException {
@Override
public void testToQuery() throws IOException {
super.testToQuery();
assertWarnings(TypeFieldMapper.TypeFieldType.TYPES_DEPRECATION_MESSAGE);
assertWarnings(TypeQueryBuilder.TYPES_DEPRECATION_MESSAGE);
}

@Override
public void testMustRewrite() throws IOException {
super.testMustRewrite();
assertWarnings(TypeFieldMapper.TypeFieldType.TYPES_DEPRECATION_MESSAGE);
assertWarnings(TypeQueryBuilder.TYPES_DEPRECATION_MESSAGE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,10 @@ public void testIndexWildcard() throws IOException {
query = new WildcardQueryBuilder("_index", "index_" + index + "*").doToQuery(context);
assertThat(query instanceof MatchNoDocsQuery, equalTo(true));
}

public void testTypeField() throws IOException {
WildcardQueryBuilder builder = QueryBuilders.wildcardQuery("_type", "doc*");
builder.doToQuery(createShardContext());
assertWarnings(QueryShardContext.TYPES_DEPRECATION_MESSAGE);
}
}