Java Code Examples for org.elasticsearch.index.mapper.Mapper#TypeParser
The following examples show how to use
org.elasticsearch.index.mapper.Mapper#TypeParser .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ESTestCase.java From crate with Apache License 2.0 | 6 votes |
/** Creates an IndicesModule for testing with the given mappers and metadata mappers. */ public static IndicesModule newTestIndicesModule(Map<String, Mapper.TypeParser> extraMappers, Map<String, MetadataFieldMapper.TypeParser> extraMetadataMappers) { return new IndicesModule(Collections.singletonList( new MapperPlugin() { @Override public Map<String, Mapper.TypeParser> getMappers() { return extraMappers; } @Override public Map<String, MetadataFieldMapper.TypeParser> getMetadataMappers() { return extraMetadataMappers; } } )); }
Example 2
Source File: MapperTestUtils.java From elasticsearch-analysis-baseform with Apache License 2.0 | 6 votes |
private static Map<String, Mapper.TypeParser> registerBuiltInMappers() { Map<String, Mapper.TypeParser> mapperParsers = new LinkedHashMap<>(); mapperParsers.put(ByteFieldMapper.CONTENT_TYPE, new ByteFieldMapper.TypeParser()); mapperParsers.put(ShortFieldMapper.CONTENT_TYPE, new ShortFieldMapper.TypeParser()); mapperParsers.put(IntegerFieldMapper.CONTENT_TYPE, new IntegerFieldMapper.TypeParser()); mapperParsers.put(LongFieldMapper.CONTENT_TYPE, new LongFieldMapper.TypeParser()); mapperParsers.put(FloatFieldMapper.CONTENT_TYPE, new FloatFieldMapper.TypeParser()); mapperParsers.put(DoubleFieldMapper.CONTENT_TYPE, new DoubleFieldMapper.TypeParser()); mapperParsers.put(BooleanFieldMapper.CONTENT_TYPE, new BooleanFieldMapper.TypeParser()); mapperParsers.put(BinaryFieldMapper.CONTENT_TYPE, new BinaryFieldMapper.TypeParser()); mapperParsers.put(DateFieldMapper.CONTENT_TYPE, new DateFieldMapper.TypeParser()); mapperParsers.put(IpFieldMapper.CONTENT_TYPE, new IpFieldMapper.TypeParser()); mapperParsers.put(StringFieldMapper.CONTENT_TYPE, new StringFieldMapper.TypeParser()); mapperParsers.put(TokenCountFieldMapper.CONTENT_TYPE, new TokenCountFieldMapper.TypeParser()); mapperParsers.put(ObjectMapper.CONTENT_TYPE, new ObjectMapper.TypeParser()); mapperParsers.put(ObjectMapper.NESTED_CONTENT_TYPE, new ObjectMapper.TypeParser()); mapperParsers.put(TypeParsers.MULTI_FIELD_CONTENT_TYPE, TypeParsers.multiFieldConverterTypeParser); mapperParsers.put(CompletionFieldMapper.CONTENT_TYPE, new CompletionFieldMapper.TypeParser()); mapperParsers.put(GeoPointFieldMapper.CONTENT_TYPE, new GeoPointFieldMapper.TypeParser()); return mapperParsers; }
Example 3
Source File: MapperTestUtils.java From elasticsearch-analysis-baseform with Apache License 2.0 | 6 votes |
public static DocumentMapperParser newDocumentMapperParser(Settings settings) { Settings forcedSettings = Settings.builder() .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .put(settings) .build(); SimilarityLookupService similarityLookupService = newSimilarityLookupService(forcedSettings); Map<String, Mapper.TypeParser> mappers = registerBuiltInMappers(); Map<String, MetadataFieldMapper.TypeParser> metadataMappers = registerBuiltInMetadataMappers(); MapperRegistry mapperRegistry = new MapperRegistry(mappers, metadataMappers); MapperService mapperService = new MapperService(new Index("test"), forcedSettings, newAnalysisService(forcedSettings), similarityLookupService, null, mapperRegistry); return new DocumentMapperParser( forcedSettings, mapperService, newAnalysisService(forcedSettings), similarityLookupService, null, mapperRegistry); }
Example 4
Source File: BundlePlugin.java From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 | 6 votes |
@Override public Map<String, Mapper.TypeParser> getMappers() { Map<String, Mapper.TypeParser> extra = new LinkedHashMap<>(); if (settings.getAsBoolean("plugins.xbib.standardnumber.enabled", true)) { extra.put(StandardnumberMapper.MAPPER_TYPE, standardNumberTypeParser); } if (settings.getAsBoolean("plugins.xbib.reference.enabled", true)) { extra.put(ReferenceMapper.CONTENT_TYPE, referenceMapperTypeParser); } if (settings.getAsBoolean("plugins.xbib.langdetect.enabled", true)) { extra.put(LangdetectMapper.CONTENT_TYPE, new LangdetectMapper.TypeParser()); } if (settings.getAsBoolean("plugins.xbib.icu.enabled", true)) { extra.put(IcuCollationKeyFieldMapper.CONTENT_TYPE, new IcuCollationKeyFieldMapper.TypeParser()); } return extra; }
Example 5
Source File: MapperTestUtils.java From elasticsearch-analysis-baseform with Apache License 2.0 | 5 votes |
public static MapperService newMapperService(Settings settings, Client client) { Settings indexSettings = Settings.builder() .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .put("path.home", System.getProperty("path.home")) .put("client.type", "node") .put(settings) .build(); Index index = new Index("test"); Injector parentInjector = new ModulesBuilder() .add(new SettingsModule(indexSettings), new EnvironmentModule(new Environment(indexSettings))) .createInjector(); AnalysisModule analysisModule = new AnalysisModule(indexSettings, parentInjector.getInstance(IndicesAnalysisService.class)); new AnalysisBaseformPlugin(settings).onModule(analysisModule); Injector injector = new ModulesBuilder().add(new IndexSettingsModule(index, indexSettings), new IndexNameModule(index), analysisModule) .createChildInjector(parentInjector); AnalysisService analysisService = injector.getInstance(AnalysisService.class); SimilarityLookupService similarityLookupService = new SimilarityLookupService(index, indexSettings); Map<String, Mapper.TypeParser> mappers = registerBuiltInMappers(); Map<String, MetadataFieldMapper.TypeParser> metadataMappers = registerBuiltInMetadataMappers(); MapperRegistry mapperRegistry = new MapperRegistry(mappers, metadataMappers); return new MapperService(new Index("test"), indexSettings, analysisService, similarityLookupService, null, mapperRegistry); }
Example 6
Source File: IndicesModule.java From crate with Apache License 2.0 | 5 votes |
private Map<String, Mapper.TypeParser> getMappers(List<MapperPlugin> mapperPlugins) { Map<String, Mapper.TypeParser> mappers = new LinkedHashMap<>(); // builtin mappers for (NumberFieldMapper.NumberType type : NumberFieldMapper.NumberType.values()) { mappers.put(type.typeName(), new NumberFieldMapper.TypeParser(type)); } mappers.put(BooleanFieldMapper.CONTENT_TYPE, new BooleanFieldMapper.TypeParser()); mappers.put(DateFieldMapper.CONTENT_TYPE, new DateFieldMapper.TypeParser()); mappers.put(IpFieldMapper.CONTENT_TYPE, new IpFieldMapper.TypeParser()); mappers.put(TextFieldMapper.CONTENT_TYPE, new TextFieldMapper.TypeParser()); mappers.put(KeywordFieldMapper.CONTENT_TYPE, new KeywordFieldMapper.TypeParser()); mappers.put(ObjectMapper.CONTENT_TYPE, new ObjectMapper.TypeParser()); mappers.put(FieldAliasMapper.CONTENT_TYPE, new FieldAliasMapper.TypeParser()); mappers.put(GeoPointFieldMapper.CONTENT_TYPE, new GeoPointFieldMapper.TypeParser()); if (ShapesAvailability.JTS_AVAILABLE && ShapesAvailability.SPATIAL4J_AVAILABLE) { mappers.put(GeoShapeFieldMapper.CONTENT_TYPE, new GeoShapeFieldMapper.TypeParser()); } for (MapperPlugin mapperPlugin : mapperPlugins) { for (Map.Entry<String, Mapper.TypeParser> entry : mapperPlugin.getMappers().entrySet()) { if (mappers.put(entry.getKey(), entry.getValue()) != null) { throw new IllegalArgumentException("Mapper [" + entry.getKey() + "] is already registered"); } } } return Collections.unmodifiableMap(mappers); }
Example 7
Source File: IndicesModule.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** * Register a mapper for the given type. */ public synchronized void registerMapper(String type, Mapper.TypeParser parser) { if (mapperParsers.containsKey(type)) { throw new IllegalArgumentException("A mapper is already registered for type [" + type + "]"); } mapperParsers.put(type, parser); }
Example 8
Source File: RootObjectMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
public Mapper.Builder findTemplateBuilder(ParseContext context, String name, String dynamicType, String matchType) { DynamicTemplate dynamicTemplate = findTemplate(context.path(), name, matchType); if (dynamicTemplate == null) { return null; } Mapper.TypeParser.ParserContext parserContext = context.docMapperParser().parserContext(name); String mappingType = dynamicTemplate.mappingType(dynamicType); Mapper.TypeParser typeParser = parserContext.typeParser(mappingType); if (typeParser == null) { throw new MapperParsingException("failed to find type parsed [" + mappingType + "] for [" + name + "]"); } return typeParser.parse(name, dynamicTemplate.mappingForName(name, dynamicType), parserContext); }
Example 9
Source File: MinHashPlugin.java From elasticsearch-minhash with Apache License 2.0 | 4 votes |
@Override public Map<String, Mapper.TypeParser> getMappers() { return Collections.<String, Mapper.TypeParser> singletonMap(MinHashFieldMapper.CONTENT_TYPE, new MinHashFieldMapper.TypeParser()); }
Example 10
Source File: TypeParsers.java From Elasticsearch with Apache License 2.0 | 4 votes |
public static boolean parseMultiField(FieldMapper.Builder builder, String name, Mapper.TypeParser.ParserContext parserContext, String propName, Object propNode) { parserContext = parserContext.createMultiFieldContext(parserContext); if (propName.equals("path") && parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1)) { builder.multiFieldPathType(parsePathType(name, propNode.toString())); return true; } else if (propName.equals("fields")) { final Map<String, Object> multiFieldsPropNodes; if (propNode instanceof List && ((List<?>) propNode).isEmpty()) { multiFieldsPropNodes = Collections.emptyMap(); } else if (propNode instanceof Map) { multiFieldsPropNodes = (Map<String, Object>) propNode; } else { throw new MapperParsingException("expected map for property [fields] on field [" + propNode + "] or " + "[" + propName + "] but got a " + propNode.getClass()); } for (Map.Entry<String, Object> multiFieldEntry : multiFieldsPropNodes.entrySet()) { String multiFieldName = multiFieldEntry.getKey(); if (multiFieldName.contains(".")) { throw new MapperParsingException("Field name [" + multiFieldName + "] which is a multi field of [" + name + "] cannot contain '.'"); } if (!(multiFieldEntry.getValue() instanceof Map)) { throw new MapperParsingException("illegal field [" + multiFieldName + "], only fields can be specified inside fields"); } @SuppressWarnings("unchecked") Map<String, Object> multiFieldNodes = (Map<String, Object>) multiFieldEntry.getValue(); String type; Object typeNode = multiFieldNodes.get("type"); if (typeNode != null) { type = typeNode.toString(); } else { throw new MapperParsingException("no type specified for property [" + multiFieldName + "]"); } if (type.equals(ObjectMapper.CONTENT_TYPE) || type.equals(ObjectMapper.NESTED_CONTENT_TYPE)) { throw new MapperParsingException("Type [" + type + "] cannot be used in multi field"); } Mapper.TypeParser typeParser = parserContext.typeParser(type); if (typeParser == null) { throw new MapperParsingException("no handler for type [" + type + "] declared on field [" + multiFieldName + "]"); } builder.addMultiField(typeParser.parse(multiFieldName, multiFieldNodes, parserContext)); multiFieldNodes.remove("type"); DocumentMapperParser.checkNoRemainingFields(propName, multiFieldNodes, parserContext.indexVersionCreated()); } return true; } return false; }
Example 11
Source File: ObjectMapper.java From Elasticsearch with Apache License 2.0 | 4 votes |
protected static void parseProperties(ObjectMapper.Builder objBuilder, Map<String, Object> propsNode, ParserContext parserContext) { Iterator<Map.Entry<String, Object>> iterator = propsNode.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<String, Object> entry = iterator.next(); String fieldName = entry.getKey(); if (fieldName.contains(".")) { throw new MapperParsingException("Field name [" + fieldName + "] cannot contain '.'"); } // Should accept empty arrays, as a work around for when the // user can't provide an empty Map. (PHP for example) boolean isEmptyList = entry.getValue() instanceof List && ((List<?>) entry.getValue()).isEmpty(); if (entry.getValue() instanceof Map) { @SuppressWarnings("unchecked") Map<String, Object> propNode = (Map<String, Object>) entry.getValue(); /* mark delete field when reindex */ Object deleteNode = propNode.get("delete"); if (deleteNode != null && deleteNode.toString().equals("true")) { /* TODO GaoPan: mark delete field when reindex */ iterator.remove(); } else { String type; Object typeNode = propNode.get("type"); if (typeNode != null) { type = typeNode.toString(); } else { // lets see if we can derive this... if (propNode.get("properties") != null) { type = ObjectMapper.CONTENT_TYPE; } else if (propNode.size() == 1 && propNode.get("enabled") != null) { // if there is a single property with the enabled // flag on it, make it an object // (usually, setting enabled to false to not index // any type, including core values, which type = ObjectMapper.CONTENT_TYPE; } else { throw new MapperParsingException("No type specified for field [" + fieldName + "]"); } } Mapper.TypeParser typeParser = parserContext.typeParser(type); if (typeParser == null) { throw new MapperParsingException("No handler for type [" + type + "] declared on field [" + fieldName + "]"); } objBuilder.add(typeParser.parse(fieldName, propNode, parserContext)); propNode.remove("type"); DocumentMapperParser.checkNoRemainingFields(fieldName, propNode, parserContext.indexVersionCreated()); iterator.remove(); } } else if (isEmptyList) { iterator.remove(); } else { throw new MapperParsingException("Expected map for property [fields] on field [" + fieldName + "] but got a " + fieldName.getClass()); } } DocumentMapperParser.checkNoRemainingFields(propsNode, parserContext.indexVersionCreated(), "DocType mapping definition has unsupported parameters: "); }
Example 12
Source File: PluginLoaderPlugin.java From crate with Apache License 2.0 | 4 votes |
@Override public Map<String, Mapper.TypeParser> getMappers() { return sqlPlugin.getMappers(); }
Example 13
Source File: MapperRegistry.java From crate with Apache License 2.0 | 4 votes |
public MapperRegistry(Map<String, Mapper.TypeParser> mapperParsers, Map<String, MetadataFieldMapper.TypeParser> metadataMapperParsers, Function<String, Predicate<String>> fieldFilter) { this.mapperParsers = Collections.unmodifiableMap(new LinkedHashMap<>(mapperParsers)); this.metadataMapperParsers = Collections.unmodifiableMap(new LinkedHashMap<>(metadataMapperParsers)); this.fieldFilter = fieldFilter; }
Example 14
Source File: SQLPlugin.java From crate with Apache License 2.0 | 4 votes |
@Override public Map<String, Mapper.TypeParser> getMappers() { return Collections.singletonMap(ArrayMapper.CONTENT_TYPE, new ArrayTypeParser()); }
Example 15
Source File: MapperRegistry.java From Elasticsearch with Apache License 2.0 | 4 votes |
public MapperRegistry(Map<String, Mapper.TypeParser> mapperParsers, Map<String, MetadataFieldMapper.TypeParser> metadataMapperParsers) { this.mapperParsers = Collections.unmodifiableMap(new LinkedHashMap<>(mapperParsers)); this.metadataMapperParsers = Collections.unmodifiableMap(new LinkedHashMap<>(metadataMapperParsers)); }
Example 16
Source File: MapperRegistry.java From Elasticsearch with Apache License 2.0 | 2 votes |
/** * Return a map of the mappers that have been registered. The * returned map uses the type of the field as a key. */ public Map<String, Mapper.TypeParser> getMapperParsers() { return mapperParsers; }
Example 17
Source File: MapperRegistry.java From crate with Apache License 2.0 | 2 votes |
/** * Return a map of the mappers that have been registered. The * returned map uses the type of the field as a key. */ public Map<String, Mapper.TypeParser> getMapperParsers() { return mapperParsers; }
Example 18
Source File: MapperPlugin.java From crate with Apache License 2.0 | 2 votes |
/** * Returns additional mapper implementations added by this plugin. * <p> * The key of the returned {@link Map} is the unique name for the mapper which will be used * as the mapping {@code type}, and the value is a {@link Mapper.TypeParser} to parse the * mapper settings into a {@link Mapper}. */ default Map<String, Mapper.TypeParser> getMappers() { return Collections.emptyMap(); }