Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay _uid field data deprecation warning #30651

Merged
merged 1 commit into from
May 16, 2018
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 @@ -113,11 +113,11 @@ public String typeName() {
@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
if (indexOptions() == IndexOptions.NONE) {
DEPRECATION_LOGGER.deprecated("Fielddata access on the _uid field is deprecated, use _id instead");
return new IndexFieldData.Builder() {
@Override
public IndexFieldData<?> build(IndexSettings indexSettings, MappedFieldType fieldType, IndexFieldDataCache cache,
CircuitBreakerService breakerService, MapperService mapperService) {
DEPRECATION_LOGGER.deprecated("Fielddata access on the _uid field is deprecated, use _id instead");
MappedFieldType idFieldType = mapperService.fullName(IdFieldMapper.NAME);
IndexFieldData<?> idFieldData = idFieldType.fielddataBuilder(fullyQualifiedIndexName)
.build(indexSettings, idFieldType, cache, breakerService, mapperService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,25 @@
import org.elasticsearch.Version;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.UUIDs;
import org.elasticsearch.common.breaker.CircuitBreaker;
import org.elasticsearch.common.breaker.NoopCircuitBreaker;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.UidFieldMapper;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
import org.mockito.Mockito;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;

import static org.mockito.Matchers.any;

public class UidFieldTypeTests extends FieldTypeTestCase {
@Override
protected MappedFieldType createDefaultFieldType() {
Expand Down Expand Up @@ -132,4 +141,35 @@ public void testTermsQuery() throws Exception {
query = ft.termQuery("type2#id", context);
assertEquals(new TermInSetQuery("_id"), query);
}

public void testIsAggregatable() {
Settings indexSettings = Settings.builder()
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
.build();
IndexMetaData indexMetaData = IndexMetaData.builder(IndexMetaData.INDEX_UUID_NA_VALUE).settings(indexSettings).build();
IndexSettings mockSettings = new IndexSettings(indexMetaData, Settings.EMPTY);
MappedFieldType ft = UidFieldMapper.defaultFieldType(mockSettings);
assertTrue(ft.isAggregatable());
}

public void testFieldDataDeprecation() {
Settings indexSettings = Settings.builder()
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
.build();
IndexMetaData indexMetaData = IndexMetaData.builder(IndexMetaData.INDEX_UUID_NA_VALUE).settings(indexSettings).build();
IndexSettings mockSettings = new IndexSettings(indexMetaData, Settings.EMPTY);
MappedFieldType ft = UidFieldMapper.defaultFieldType(mockSettings);
IndexFieldData.Builder builder = ft.fielddataBuilder("");
MapperService mockMapper = Mockito.mock(MapperService.class);
Mockito.when(mockMapper.fullName(any())).thenReturn(new IdFieldMapper.IdFieldType());
Mockito.when(mockMapper.types()).thenReturn(Collections.singleton("doc"));
builder.build(mockSettings, ft, null, new NoneCircuitBreakerService(), mockMapper);
assertWarnings("Fielddata access on the _uid field is deprecated, use _id instead");
}
}