Skip to content

Commit

Permalink
Remove the deprecated method DocumentFieldMappers#getFieldMapper. (#3…
Browse files Browse the repository at this point in the history
  • Loading branch information
jtibshirani committed Jul 18, 2018
1 parent 6cfa032 commit c3ff6ce
Show file tree
Hide file tree
Showing 26 changed files with 441 additions and 441 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,11 @@ public DocumentFieldMappers(Collection<FieldMapper> mappers,
this.searchQuoteAnalyzer = new FieldNameAnalyzer(searchQuoteAnalyzers);
}

/**
* @deprecated Use {@link DocumentFieldMappers#getMapper} instead. To access a field's
* type information, instead use {@link MapperService#fullName}.
*/
@Deprecated
public FieldMapper getFieldMapper(String field) {
Mapper mapper = getMapper(field);
return (mapper instanceof FieldMapper) ? (FieldMapper) mapper : null;
}

/**
* Returns the leaf mapper associated with this field name. Note that the returned mapper
* could be either a concrete {@link FieldMapper}, or a {@link FieldAliasMapper}.
*
* To access a field's type information, {@link MapperService#fullName} should be used instead.
*/
public Mapper getMapper(String field) {
return fieldMappers.get(field);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
import org.apache.lucene.analysis.Analyzer;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.indices.analysis.PreBuiltAnalyzers;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESSingleNodeTestCase;
Expand Down Expand Up @@ -84,14 +83,14 @@ public void testThatAnalyzersAreUsedInMapping() throws IOException {

NamedAnalyzer namedAnalyzer = new PreBuiltAnalyzerProvider(analyzerName, AnalyzerScope.INDEX, randomPreBuiltAnalyzer.getAnalyzer(randomVersion)).get();

String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field").field("type", "text").field("analyzer", analyzerName).endObject().endObject()
.endObject().endObject());
DocumentMapper docMapper = createIndex("test", indexSettings).mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
.endObject().endObject();
MapperService mapperService = createIndex("test", indexSettings, "type", mapping).mapperService();

FieldMapper fieldMapper = docMapper.mappers().getFieldMapper("field");
assertThat(fieldMapper.fieldType().searchAnalyzer(), instanceOf(NamedAnalyzer.class));
NamedAnalyzer fieldMapperNamedAnalyzer = fieldMapper.fieldType().searchAnalyzer();
MappedFieldType fieldType = mapperService.fullName("field");
assertThat(fieldType.searchAnalyzer(), instanceOf(NamedAnalyzer.class));
NamedAnalyzer fieldMapperNamedAnalyzer = fieldType.searchAnalyzer();

assertThat(fieldMapperNamedAnalyzer.analyzer(), is(namedAnalyzer.analyzer()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.elasticsearch.common.compress.CompressorFactory;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.plugins.Plugin;
Expand All @@ -49,32 +51,32 @@ protected Collection<Class<? extends Plugin>> getPlugins() {
}

public void testDefaultMapping() throws Exception {
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties")
.startObject("field")
.field("type", "binary")
.endObject()
.endObject()
.endObject().endObject());
.endObject().endObject();

DocumentMapper mapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
MapperService mapperService = createIndex("test", Settings.EMPTY, "type", mapping).mapperService();
MappedFieldType fieldType = mapperService.fullName("field");

FieldMapper fieldMapper = mapper.mappers().getFieldMapper("field");
assertThat(fieldMapper, instanceOf(BinaryFieldMapper.class));
assertThat(fieldMapper.fieldType().stored(), equalTo(false));
assertThat(fieldType, instanceOf(BinaryFieldMapper.BinaryFieldType.class));
assertThat(fieldType.stored(), equalTo(false));
}

public void testStoredValue() throws IOException {
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties")
.startObject("field")
.field("type", "binary")
.field("store", true)
.endObject()
.endObject()
.endObject().endObject());
.endObject().endObject();

DocumentMapper mapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
MapperService mapperService = createIndex("test", Settings.EMPTY, "type", mapping).mapperService();

// case 1: a simple binary value
final byte[] binaryValue1 = new byte[100];
Expand All @@ -89,13 +91,14 @@ public void testStoredValue() throws IOException {
assertTrue(CompressorFactory.isCompressed(new BytesArray(binaryValue2)));

for (byte[] value : Arrays.asList(binaryValue1, binaryValue2)) {
ParsedDocument doc = mapper.parse(SourceToParse.source("test", "type", "id",
ParsedDocument doc = mapperService.documentMapper().parse(SourceToParse.source("test", "type", "id",
BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", value).endObject()),
XContentType.JSON));
BytesRef indexedValue = doc.rootDoc().getBinaryValue("field");
assertEquals(new BytesRef(value), indexedValue);
FieldMapper fieldMapper = mapper.mappers().getFieldMapper("field");
Object originalValue = fieldMapper.fieldType().valueForDisplay(indexedValue);

MappedFieldType fieldType = mapperService.fullName("field");
Object originalValue = fieldType.valueForDisplay(indexedValue);
assertEquals(new BytesArray(value), originalValue);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
public class BooleanFieldMapperTests extends ESSingleNodeTestCase {
private IndexService indexService;
private DocumentMapperParser parser;
private DocumentMapperParser preEs6Parser;

@Before
public void setup() {
Expand Down Expand Up @@ -101,7 +100,7 @@ public void testSerialization() throws IOException {
.endObject().endObject());

DocumentMapper defaultMapper = parser.parse("type", new CompressedXContent(mapping));
FieldMapper mapper = defaultMapper.mappers().getFieldMapper("field");
Mapper mapper = defaultMapper.mappers().getMapper("field");
XContentBuilder builder = XContentFactory.jsonBuilder().startObject();
mapper.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
Expand All @@ -117,7 +116,7 @@ public void testSerialization() throws IOException {
.endObject().endObject());

defaultMapper = parser.parse("type", new CompressedXContent(mapping));
mapper = defaultMapper.mappers().getFieldMapper("field");
mapper = defaultMapper.mappers().getMapper("field");
builder = XContentFactory.jsonBuilder().startObject();
mapper.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public void testCamelCaseFieldNameStaysAsIs() throws Exception {
.setSource(doc.dynamicMappingsUpdate().toString(), XContentType.JSON).get();

documentMapper = index.mapperService().documentMapper("type");
assertNotNull(documentMapper.mappers().getFieldMapper("thisIsCamelCase"));
assertNull(documentMapper.mappers().getFieldMapper("this_is_camel_case"));
assertNotNull(documentMapper.mappers().getMapper("thisIsCamelCase"));
assertNull(documentMapper.mappers().getMapper("this_is_camel_case"));

documentMapper = index.mapperService().documentMapperParser().parse("type", documentMapper.mappingSource());

assertNotNull(documentMapper.mappers().getFieldMapper("thisIsCamelCase"));
assertNull(documentMapper.mappers().getFieldMapper("this_is_camel_case"));
assertNotNull(documentMapper.mappers().getMapper("thisIsCamelCase"));
assertNull(documentMapper.mappers().getMapper("this_is_camel_case"));
}
}
Loading

0 comments on commit c3ff6ce

Please sign in to comment.