mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-27 18:38:41 +00:00
Simplify root mapper builder creation
This commit is contained in:
parent
adcc0683b8
commit
00bcce79f7
@ -28,71 +28,14 @@ import org.elasticsearch.index.mapper.ip.IpFieldMapper;
|
||||
import org.elasticsearch.index.mapper.object.ObjectMapper;
|
||||
import org.elasticsearch.index.mapper.object.RootObjectMapper;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final class MapperBuilders {
|
||||
|
||||
private MapperBuilders() {
|
||||
|
||||
}
|
||||
private MapperBuilders() {}
|
||||
|
||||
public static DocumentMapper.Builder doc(String index, Settings settings, RootObjectMapper.Builder objectBuilder, MapperService mapperService) {
|
||||
return new DocumentMapper.Builder(index, settings, objectBuilder, mapperService);
|
||||
}
|
||||
|
||||
public static SourceFieldMapper.Builder source() {
|
||||
return new SourceFieldMapper.Builder();
|
||||
}
|
||||
|
||||
public static IdFieldMapper.Builder id(MappedFieldType existing) {
|
||||
return new IdFieldMapper.Builder(existing);
|
||||
}
|
||||
|
||||
public static RoutingFieldMapper.Builder routing(MappedFieldType existing) {
|
||||
return new RoutingFieldMapper.Builder(existing);
|
||||
}
|
||||
|
||||
public static UidFieldMapper.Builder uid(MappedFieldType existing) {
|
||||
return new UidFieldMapper.Builder(existing);
|
||||
}
|
||||
|
||||
public static SizeFieldMapper.Builder size(MappedFieldType existing) {
|
||||
return new SizeFieldMapper.Builder(existing);
|
||||
}
|
||||
|
||||
public static VersionFieldMapper.Builder version() {
|
||||
return new VersionFieldMapper.Builder();
|
||||
}
|
||||
|
||||
public static TypeFieldMapper.Builder type(MappedFieldType existing) {
|
||||
return new TypeFieldMapper.Builder(existing);
|
||||
}
|
||||
|
||||
public static FieldNamesFieldMapper.Builder fieldNames() {
|
||||
return new FieldNamesFieldMapper.Builder();
|
||||
}
|
||||
|
||||
public static IndexFieldMapper.Builder index(MappedFieldType existing) {
|
||||
return new IndexFieldMapper.Builder(existing);
|
||||
}
|
||||
|
||||
public static TimestampFieldMapper.Builder timestamp(MappedFieldType existing) {
|
||||
return new TimestampFieldMapper.Builder(existing);
|
||||
}
|
||||
|
||||
public static TTLFieldMapper.Builder ttl() {
|
||||
return new TTLFieldMapper.Builder();
|
||||
}
|
||||
|
||||
public static ParentFieldMapper.Builder parent() {
|
||||
return new ParentFieldMapper.Builder();
|
||||
}
|
||||
|
||||
public static AllFieldMapper.Builder all(MappedFieldType existing) {
|
||||
return new AllFieldMapper.Builder(existing);
|
||||
}
|
||||
|
||||
public static RootObjectMapper.Builder rootObject(String name) {
|
||||
return new RootObjectMapper.Builder(name);
|
||||
}
|
||||
|
@ -52,7 +52,6 @@ import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBooleanValue;
|
||||
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeMapValue;
|
||||
import static org.elasticsearch.index.mapper.MapperBuilders.all;
|
||||
import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
|
||||
|
||||
/**
|
||||
@ -119,7 +118,7 @@ public class AllFieldMapper extends AbstractFieldMapper implements RootMapper {
|
||||
public static class TypeParser implements Mapper.TypeParser {
|
||||
@Override
|
||||
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
|
||||
AllFieldMapper.Builder builder = all(parserContext.mapperService().fullName(NAME));
|
||||
Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
|
||||
|
||||
// parseField below will happily parse the doc_values setting, but it is then never passed to
|
||||
// the AllFieldMapper ctor in the builder since it is not valid. Here we validate
|
||||
|
@ -47,7 +47,6 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBooleanValue;
|
||||
import static org.elasticsearch.index.mapper.MapperBuilders.fieldNames;
|
||||
import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
|
||||
|
||||
/**
|
||||
@ -83,8 +82,8 @@ public class FieldNamesFieldMapper extends AbstractFieldMapper implements RootMa
|
||||
public static class Builder extends AbstractFieldMapper.Builder<Builder, FieldNamesFieldMapper> {
|
||||
private boolean enabled = Defaults.ENABLED;
|
||||
|
||||
public Builder() {
|
||||
super(Defaults.NAME, Defaults.FIELD_TYPE);
|
||||
public Builder(MappedFieldType existing) {
|
||||
super(Defaults.NAME, existing == null ? Defaults.FIELD_TYPE : existing);
|
||||
indexName = Defaults.NAME;
|
||||
}
|
||||
|
||||
@ -116,7 +115,7 @@ public class FieldNamesFieldMapper extends AbstractFieldMapper implements RootMa
|
||||
throw new IllegalArgumentException("type="+CONTENT_TYPE+" is not supported on indices created before version 1.3.0. Is your cluster running multiple datanode versions?");
|
||||
}
|
||||
|
||||
FieldNamesFieldMapper.Builder builder = fieldNames();
|
||||
Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
|
||||
if (parserContext.indexVersionCreated().before(Version.V_2_0_0)) {
|
||||
parseField(builder, builder.name, node, parserContext);
|
||||
}
|
||||
|
@ -58,7 +58,6 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.index.mapper.MapperBuilders.id;
|
||||
import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
|
||||
|
||||
/**
|
||||
@ -120,7 +119,7 @@ public class IdFieldMapper extends AbstractFieldMapper implements RootMapper {
|
||||
if (parserContext.indexVersionCreated().onOrAfter(Version.V_2_0_0)) {
|
||||
throw new MapperParsingException(NAME + " is not configurable");
|
||||
}
|
||||
IdFieldMapper.Builder builder = id(parserContext.mapperService().fullName(NAME));
|
||||
Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
|
||||
parseField(builder, builder.name, node, parserContext);
|
||||
for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
|
||||
Map.Entry<String, Object> entry = iterator.next();
|
||||
|
@ -99,7 +99,7 @@ public class IndexFieldMapper extends AbstractFieldMapper implements RootMapper
|
||||
public static class TypeParser implements Mapper.TypeParser {
|
||||
@Override
|
||||
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
|
||||
IndexFieldMapper.Builder builder = MapperBuilders.index(parserContext.mapperService().fullName(NAME));
|
||||
Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
|
||||
if (parserContext.indexVersionCreated().before(Version.V_2_0_0)) {
|
||||
parseField(builder, builder.name, node, parserContext);
|
||||
}
|
||||
|
@ -64,10 +64,8 @@ import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeMa
|
||||
public class ParentFieldMapper extends AbstractFieldMapper implements RootMapper {
|
||||
|
||||
public static final String NAME = "_parent";
|
||||
|
||||
public static final String CONTENT_TYPE = "_parent";
|
||||
|
||||
|
||||
public static class Defaults extends AbstractFieldMapper.Defaults {
|
||||
public static final String NAME = ParentFieldMapper.NAME;
|
||||
|
||||
@ -122,7 +120,7 @@ public class ParentFieldMapper extends AbstractFieldMapper implements RootMapper
|
||||
public static class TypeParser implements Mapper.TypeParser {
|
||||
@Override
|
||||
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
|
||||
ParentFieldMapper.Builder builder = MapperBuilders.parent();
|
||||
Builder builder = new Builder();
|
||||
for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
|
||||
Map.Entry<String, Object> entry = iterator.next();
|
||||
String fieldName = Strings.toUnderscoreCase(entry.getKey());
|
||||
|
@ -44,7 +44,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBooleanValue;
|
||||
import static org.elasticsearch.index.mapper.MapperBuilders.routing;
|
||||
import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
|
||||
|
||||
/**
|
||||
@ -104,7 +103,7 @@ public class RoutingFieldMapper extends AbstractFieldMapper implements RootMappe
|
||||
public static class TypeParser implements Mapper.TypeParser {
|
||||
@Override
|
||||
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
|
||||
RoutingFieldMapper.Builder builder = routing(parserContext.mapperService().fullName(NAME));
|
||||
Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
|
||||
if (parserContext.indexVersionCreated().before(Version.V_2_0_0)) {
|
||||
parseField(builder, builder.name, node, parserContext);
|
||||
}
|
||||
|
@ -43,7 +43,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBooleanValue;
|
||||
import static org.elasticsearch.index.mapper.MapperBuilders.size;
|
||||
import static org.elasticsearch.index.mapper.core.TypeParsers.parseStore;
|
||||
|
||||
public class SizeFieldMapper extends IntegerFieldMapper implements RootMapper {
|
||||
@ -101,7 +100,7 @@ public class SizeFieldMapper extends IntegerFieldMapper implements RootMapper {
|
||||
public static class TypeParser implements Mapper.TypeParser {
|
||||
@Override
|
||||
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
|
||||
SizeFieldMapper.Builder builder = size(parserContext.mapperService().fullName(NAME));
|
||||
Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
|
||||
for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
|
||||
Map.Entry<String, Object> entry = iterator.next();
|
||||
String fieldName = Strings.toUnderscoreCase(entry.getKey());
|
||||
|
@ -20,7 +20,6 @@
|
||||
package org.elasticsearch.index.mapper.internal;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.StoredField;
|
||||
import org.apache.lucene.index.IndexOptions;
|
||||
@ -63,7 +62,6 @@ import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBooleanValue;
|
||||
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeStringValue;
|
||||
import static org.elasticsearch.index.mapper.MapperBuilders.source;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -150,7 +148,7 @@ public class SourceFieldMapper extends AbstractFieldMapper implements RootMapper
|
||||
public static class TypeParser implements Mapper.TypeParser {
|
||||
@Override
|
||||
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
|
||||
SourceFieldMapper.Builder builder = source();
|
||||
Builder builder = new Builder();
|
||||
|
||||
for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
|
||||
Map.Entry<String, Object> entry = iterator.next();
|
||||
|
@ -51,7 +51,6 @@ import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBooleanValue;
|
||||
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeTimeValue;
|
||||
import static org.elasticsearch.index.mapper.MapperBuilders.ttl;
|
||||
|
||||
public class TTLFieldMapper extends LongFieldMapper implements RootMapper {
|
||||
|
||||
@ -115,7 +114,7 @@ public class TTLFieldMapper extends LongFieldMapper implements RootMapper {
|
||||
public static class TypeParser implements Mapper.TypeParser {
|
||||
@Override
|
||||
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
|
||||
TTLFieldMapper.Builder builder = ttl();
|
||||
Builder builder = new Builder();
|
||||
for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
|
||||
Map.Entry<String, Object> entry = iterator.next();
|
||||
String fieldName = Strings.toUnderscoreCase(entry.getKey());
|
||||
|
@ -50,7 +50,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBooleanValue;
|
||||
import static org.elasticsearch.index.mapper.MapperBuilders.timestamp;
|
||||
import static org.elasticsearch.index.mapper.core.TypeParsers.parseDateTimeFormatter;
|
||||
import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
|
||||
|
||||
@ -163,7 +162,7 @@ public class TimestampFieldMapper extends DateFieldMapper implements RootMapper
|
||||
public static class TypeParser implements Mapper.TypeParser {
|
||||
@Override
|
||||
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
|
||||
TimestampFieldMapper.Builder builder = timestamp(parserContext.mapperService().fullName(NAME));
|
||||
Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
|
||||
if (parserContext.indexVersionCreated().before(Version.V_2_0_0)) {
|
||||
parseField(builder, builder.name, node, parserContext);
|
||||
}
|
||||
|
@ -50,7 +50,6 @@ import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.index.mapper.MapperBuilders.type;
|
||||
import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
|
||||
|
||||
/**
|
||||
@ -99,7 +98,7 @@ public class TypeFieldMapper extends AbstractFieldMapper implements RootMapper {
|
||||
if (parserContext.indexVersionCreated().onOrAfter(Version.V_2_0_0)) {
|
||||
throw new MapperParsingException(NAME + " is not configurable");
|
||||
}
|
||||
TypeFieldMapper.Builder builder = type(parserContext.mapperService().fullName(NAME));
|
||||
Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
|
||||
parseField(builder, builder.name, node, parserContext);
|
||||
return builder;
|
||||
}
|
||||
|
@ -46,7 +46,6 @@ import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.index.mapper.MapperBuilders.uid;
|
||||
import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
|
||||
|
||||
/**
|
||||
@ -100,7 +99,7 @@ public class UidFieldMapper extends AbstractFieldMapper implements RootMapper {
|
||||
if (parserContext.indexVersionCreated().onOrAfter(Version.V_2_0_0)) {
|
||||
throw new MapperParsingException(NAME + " is not configurable");
|
||||
}
|
||||
Builder builder = uid(parserContext.mapperService().fullName(NAME));
|
||||
Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
|
||||
parseField(builder, builder.name, node, parserContext);
|
||||
return builder;
|
||||
}
|
||||
|
@ -42,8 +42,6 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.index.mapper.MapperBuilders.version;
|
||||
|
||||
/** Mapper for the _version field. */
|
||||
public class VersionFieldMapper extends AbstractFieldMapper implements RootMapper {
|
||||
|
||||
@ -77,11 +75,10 @@ public class VersionFieldMapper extends AbstractFieldMapper implements RootMappe
|
||||
public static class TypeParser implements Mapper.TypeParser {
|
||||
@Override
|
||||
public Mapper.Builder<?, ?> parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
|
||||
Builder builder = version();
|
||||
Builder builder = new Builder();
|
||||
for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
|
||||
Map.Entry<String, Object> entry = iterator.next();
|
||||
String fieldName = Strings.toUnderscoreCase(entry.getKey());
|
||||
Object fieldNode = entry.getValue();
|
||||
if (fieldName.equals(DOC_VALUES_FORMAT) && parserContext.indexVersionCreated().before(Version.V_2_0_0)) {
|
||||
// ignore in 1.x, reject in 2.x
|
||||
iterator.remove();
|
||||
|
@ -34,6 +34,7 @@ import org.elasticsearch.index.mapper.Mapper.BuilderContext;
|
||||
import org.elasticsearch.index.mapper.MapperBuilders;
|
||||
import org.elasticsearch.index.mapper.MapperService;
|
||||
import org.elasticsearch.index.IndexService;
|
||||
import org.elasticsearch.index.mapper.internal.ParentFieldMapper;
|
||||
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
|
||||
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
|
||||
import org.junit.After;
|
||||
@ -85,7 +86,7 @@ public abstract class AbstractFieldDataTests extends ElasticsearchSingleNodeTest
|
||||
} else if (type.getType().equals("geo_point")) {
|
||||
fieldType = MapperBuilders.geoPointField(fieldName).docValues(docValues).fieldDataSettings(type.getSettings()).build(context).fieldType();
|
||||
} else if (type.getType().equals("_parent")) {
|
||||
fieldType = MapperBuilders.parent().type(fieldName).build(context).fieldType();
|
||||
fieldType = new ParentFieldMapper.Builder().type(fieldName).build(context).fieldType();
|
||||
} else if (type.getType().equals("binary")) {
|
||||
fieldType = MapperBuilders.binaryField(fieldName).docValues(docValues).fieldDataSettings(type.getSettings()).build(context).fieldType();
|
||||
} else {
|
||||
|
@ -55,8 +55,6 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFa
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class ParentFieldLoadingBwcTest extends ElasticsearchIntegrationTest {
|
||||
|
||||
private final Settings indexSettings = Settings.builder()
|
||||
@ -68,7 +66,6 @@ public class ParentFieldLoadingBwcTest extends ElasticsearchIntegrationTest {
|
||||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_6_0)
|
||||
.build();
|
||||
|
||||
@Test
|
||||
@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elasticsearch/elasticsearch/issues/9270")
|
||||
public void testParentFieldDataCacheBug() throws Exception {
|
||||
assertAcked(prepareCreate("test")
|
||||
@ -145,7 +142,6 @@ public class ParentFieldLoadingBwcTest extends ElasticsearchIntegrationTest {
|
||||
assertThat(indicesStatsResponse.getTotal().getFieldData().getFields().get("_parent"), equalTo(0l));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEagerParentFieldLoading() throws Exception {
|
||||
logger.info("testing lazy loading...");
|
||||
assertAcked(prepareCreate("test")
|
||||
@ -214,8 +210,7 @@ public class ParentFieldLoadingBwcTest extends ElasticsearchIntegrationTest {
|
||||
response = client().admin().cluster().prepareClusterStats().get();
|
||||
assertThat(response.getIndicesStats().getFieldData().getMemorySizeInBytes(), greaterThan(fielddataSizeDefault));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
public void testChangingEagerParentFieldLoadingAtRuntime() throws Exception {
|
||||
assertAcked(prepareCreate("test")
|
||||
.setSettings(indexSettings)
|
||||
|
Loading…
x
Reference in New Issue
Block a user