Java Code Examples for org.elasticsearch.index.mapper.Mapper#Builder
The following examples show how to use
org.elasticsearch.index.mapper.Mapper#Builder .
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: MinHashFieldMapper.java From elasticsearch-minhash with Apache License 2.0 | 6 votes |
@Override public Mapper.Builder parse(final String name, final Map<String, Object> node, final ParserContext parserContext) throws MapperParsingException { final MinHashFieldMapper.Builder builder = new MinHashFieldMapper.Builder( name); parseField(builder, name, node, parserContext); for (final Iterator<Map.Entry<String, Object>> iterator = node.entrySet() .iterator(); iterator.hasNext();) { final Map.Entry<String, Object> entry = iterator.next(); final String propName = entry.getKey(); final Object propNode = entry.getValue(); if (propName.equals("minhash_analyzer") && propNode != null) { final NamedAnalyzer analyzer = parserContext .getIndexAnalyzers().get(propNode.toString()); builder.minhashAnalyzer(analyzer); iterator.remove(); } else if (propName.equals("copy_bits_to") && propNode != null) { parseCopyBitsFields(propNode, builder); iterator.remove(); } } return builder; }
Example 2
Source File: IntegerFieldMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { IntegerFieldMapper.Builder builder = integerField(name); parseNumberField(builder, name, node, parserContext); for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String propName = Strings.toUnderscoreCase(entry.getKey()); Object propNode = entry.getValue(); if (propName.equals("null_value")) { if (propNode == null) { throw new MapperParsingException("Property [null_value] cannot be null."); } builder.nullValue(nodeIntegerValue(propNode)); iterator.remove(); } } return builder; }
Example 3
Source File: DoubleFieldMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { DoubleFieldMapper.Builder builder = doubleField(name); parseNumberField(builder, name, node, parserContext); for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String propName = entry.getKey(); Object propNode = entry.getValue(); if (propName.equals("nullValue") || propName.equals("null_value")) { if (propNode == null) { throw new MapperParsingException("Property [null_value] cannot be null."); } builder.nullValue(nodeDoubleValue(propNode)); iterator.remove(); } } return builder; }
Example 4
Source File: BooleanFieldMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { BooleanFieldMapper.Builder builder = booleanField(name); parseField(builder, name, node, parserContext); for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String propName = Strings.toUnderscoreCase(entry.getKey()); Object propNode = entry.getValue(); if (propName.equals("null_value")) { if (propNode == null) { throw new MapperParsingException("Property [null_value] cannot be null."); } builder.nullValue(nodeBooleanValue(propNode)); iterator.remove(); } else if (parseMultiField(builder, name, parserContext, propName, propNode)) { iterator.remove(); } } return builder; }
Example 5
Source File: FloatFieldMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { FloatFieldMapper.Builder builder = floatField(name); parseNumberField(builder, name, node, parserContext); for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String propName = Strings.toUnderscoreCase(entry.getKey()); Object propNode = entry.getValue(); if (propName.equals("null_value")) { if (propNode == null) { throw new MapperParsingException("Property [null_value] cannot be null."); } builder.nullValue(nodeFloatValue(propNode)); iterator.remove(); } } return builder; }
Example 6
Source File: ShortFieldMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { ShortFieldMapper.Builder builder = shortField(name); parseNumberField(builder, name, node, parserContext); for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String propName = Strings.toUnderscoreCase(entry.getKey()); Object propNode = entry.getValue(); if (propName.equals("null_value")) { if (propNode == null) { throw new MapperParsingException("Property [null_value] cannot be null."); } builder.nullValue(nodeShortValue(propNode)); iterator.remove(); } } return builder; }
Example 7
Source File: TokenCountFieldMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { TokenCountFieldMapper.Builder builder = tokenCountField(name); for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String propName = Strings.toUnderscoreCase(entry.getKey()); Object propNode = entry.getValue(); if (propName.equals("null_value")) { builder.nullValue(nodeIntegerValue(propNode)); iterator.remove(); } else if (propName.equals("analyzer")) { NamedAnalyzer analyzer = parserContext.analysisService().analyzer(propNode.toString()); if (analyzer == null) { throw new MapperParsingException("Analyzer [" + propNode.toString() + "] not found for field [" + name + "]"); } builder.analyzer(analyzer); iterator.remove(); } } parseNumberField(builder, name, node, parserContext); if (builder.analyzer() == null) { throw new MapperParsingException("Analyzer must be set for field [" + name + "] but wasn't."); } return builder; }
Example 8
Source File: StandardnumberMapper.java From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 | 6 votes |
@SuppressWarnings({"unchecked", "rawtypes"}) @Override public Mapper.Builder parse(String name, Map<String, Object> mapping, ParserContext parserContext) { StandardnumberMapper.Builder builder = new Builder(name, service); Iterator<Map.Entry<String, Object>> iterator = mapping.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<String, Object> entry = iterator.next(); String fieldName = entry.getKey(); Object fieldNode = entry.getValue(); switch (fieldName) { case "standardnumbers" : builder.settingsBuilder.putList("standardnumbers", XContentMapValues.nodeStringArrayValue(fieldNode)); iterator.remove(); break; default: break; } } return builder; }
Example 9
Source File: ByteFieldMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { ByteFieldMapper.Builder builder = byteField(name); parseNumberField(builder, name, node, parserContext); for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String propName = Strings.toUnderscoreCase(entry.getKey()); Object propNode = entry.getValue(); if (propName.equals("null_value")) { if (propNode == null) { throw new MapperParsingException("Property [null_value] cannot be null."); } builder.nullValue(nodeByteValue(propNode)); iterator.remove(); } } return builder; }
Example 10
Source File: RootObjectMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { ObjectMapper.Builder builder = createBuilder(name); Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<String, Object> entry = iterator.next(); String fieldName = Strings.toUnderscoreCase(entry.getKey()); Object fieldNode = entry.getValue(); if (parseObjectOrDocumentTypeProperties(fieldName, fieldNode, parserContext, builder) || processField(builder, fieldName, fieldNode)) { iterator.remove(); } } return builder; }
Example 11
Source File: ObjectMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public Y build(BuilderContext context) { ContentPath.Type origPathType = context.path().pathType(); context.path().pathType(pathType); context.path().add(name); Map<String, Mapper> mappers = new HashMap<>(); for (Mapper.Builder builder : mappersBuilders) { Mapper mapper = builder.build(context); mappers.put(mapper.simpleName(), mapper); } context.path().pathType(origPathType); context.path().remove(); ObjectMapper objectMapper = createMapper(name, context.path().fullPathAsText(name), enabled, nested, dynamic, pathType, mappers, context.indexSettings()); objectMapper = objectMapper.includeInAllIfNotSet(includeInAll); return (Y) objectMapper; }
Example 12
Source File: IpFieldMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { IpFieldMapper.Builder builder = ipField(name); parseNumberField(builder, name, node, parserContext); for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String propName = Strings.toUnderscoreCase(entry.getKey()); Object propNode = entry.getValue(); if (propName.equals("null_value")) { if (propNode == null) { throw new MapperParsingException("Property [null_value] cannot be null."); } builder.nullValue(propNode.toString()); iterator.remove(); } } return builder; }
Example 13
Source File: DateFieldMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public Mapper.Builder<?, ?> parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { DateFieldMapper.Builder builder = dateField(name); parseNumberField(builder, name, node, parserContext); boolean configuredFormat = false; for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String propName = Strings.toUnderscoreCase(entry.getKey()); Object propNode = entry.getValue(); if (propName.equals("null_value")) { if (propNode == null) { throw new MapperParsingException("Property [null_value] cannot be null."); } builder.nullValue(propNode.toString()); iterator.remove(); } else if (propName.equals("format")) { builder.dateTimeFormatter(parseDateTimeFormatter(propNode)); configuredFormat = true; iterator.remove(); } else if (propName.equals("numeric_resolution")) { builder.timeUnit(TimeUnit.valueOf(propNode.toString().toUpperCase(Locale.ROOT))); iterator.remove(); } else if (propName.equals("locale")) { builder.locale(LocaleUtils.parse(propNode.toString())); iterator.remove(); } } if (!configuredFormat) { if (parserContext.indexVersionCreated().onOrAfter(Version.V_2_0_0_beta1)) { builder.dateTimeFormatter(Defaults.DATE_TIME_FORMATTER); } else { builder.dateTimeFormatter(Defaults.DATE_TIME_FORMATTER_BEFORE_2_0); } } return builder; }
Example 14
Source File: ObjectMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { ObjectMapper.Builder builder = createBuilder(name); parseNested(name, node, 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 (parseObjectOrDocumentTypeProperties(fieldName, fieldNode, parserContext, builder) || parseObjectProperties(name, fieldName, fieldNode, parserContext, builder)) { iterator.remove(); } } return builder; }
Example 15
Source File: GeoShapeFieldMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { Builder builder = geoShapeField(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()); Object fieldNode = entry.getValue(); if (Names.TREE.equals(fieldName)) { builder.fieldType().setTree(fieldNode.toString()); iterator.remove(); } else if (Names.TREE_LEVELS.equals(fieldName)) { builder.fieldType().setTreeLevels(Integer.parseInt(fieldNode.toString())); iterator.remove(); } else if (Names.TREE_PRESISION.equals(fieldName)) { builder.fieldType().setPrecisionInMeters(DistanceUnit.parse(fieldNode.toString(), DistanceUnit.DEFAULT, DistanceUnit.DEFAULT)); iterator.remove(); } else if (Names.DISTANCE_ERROR_PCT.equals(fieldName)) { builder.fieldType().setDistanceErrorPct(Double.parseDouble(fieldNode.toString())); iterator.remove(); } else if (Names.ORIENTATION.equals(fieldName)) { builder.fieldType().setOrientation(ShapeBuilder.orientationFromString(fieldNode.toString())); iterator.remove(); } else if (Names.STRATEGY.equals(fieldName)) { builder.fieldType().setStrategyName(fieldNode.toString()); iterator.remove(); } else if (Names.COERCE.equals(fieldName)) { builder.coerce(nodeBooleanValue(fieldNode)); iterator.remove(); } else if (Names.STRATEGY_POINTS_ONLY.equals(fieldName) && builder.fieldType().strategyName.equals(SpatialStrategy.TERM.getStrategyName()) == false) { builder.fieldType().setPointsOnly(XContentMapValues.nodeBooleanValue(fieldNode)); iterator.remove(); } } return builder; }
Example 16
Source File: IcuCollationKeyFieldMapper.java From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 | 4 votes |
@Override public Mapper.Builder<?, ?> parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { Builder builder = new Builder(name); TypeParsers.parseField(builder, name, node, parserContext); for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext(); ) { Map.Entry<String, Object> entry = iterator.next(); String fieldName = entry.getKey(); Object fieldNode = entry.getValue(); switch (fieldName) { case "null_value": if (fieldNode == null) { throw new MapperParsingException("property [null_value] cannot be null"); } builder.nullValue(fieldNode.toString()); iterator.remove(); break; case "norms": builder.omitNorms(!XContentMapValues.nodeBooleanValue(fieldNode)); iterator.remove(); break; case "rules": builder.rules(XContentMapValues.nodeStringValue(fieldNode, null)); iterator.remove(); break; case "language": builder.language(XContentMapValues.nodeStringValue(fieldNode, null)); iterator.remove(); break; case "country": builder.country(XContentMapValues.nodeStringValue(fieldNode, null)); iterator.remove(); break; case "variant": builder.variant(XContentMapValues.nodeStringValue(fieldNode, null)); iterator.remove(); break; case "strength": builder.strength(XContentMapValues.nodeStringValue(fieldNode, null)); iterator.remove(); break; case "decomposition": builder.decomposition(XContentMapValues.nodeStringValue(fieldNode, null)); iterator.remove(); break; case "alternate": builder.alternate(XContentMapValues.nodeStringValue(fieldNode, null)); iterator.remove(); break; case "case_level": builder.caseLevel(XContentMapValues.nodeBooleanValue(fieldNode)); iterator.remove(); break; case "case_first": builder.caseFirst(XContentMapValues.nodeStringValue(fieldNode, null)); iterator.remove(); break; case "numeric": builder.numeric(XContentMapValues.nodeBooleanValue(fieldNode)); iterator.remove(); break; default: break; } } return builder; }
Example 17
Source File: BaseGeoPointFieldMapper.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public Mapper.Builder<?, ?> parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { Builder builder; if (parserContext.indexVersionCreated().before(Version.V_2_2_0)) { builder = new GeoPointFieldMapperLegacy.Builder(name); } else { builder = new GeoPointFieldMapper.Builder(name); } parseField(builder, name, node, parserContext); for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String propName = Strings.toUnderscoreCase(entry.getKey()); Object propNode = entry.getValue(); if (propName.equals("lat_lon")) { deprecationLogger.deprecated(CONTENT_TYPE + " lat_lon parameter is deprecated and will be removed " + "in the next major release"); builder.enableLatLon(XContentMapValues.nodeBooleanValue(propNode)); iterator.remove(); } else if (propName.equals("precision_step")) { deprecationLogger.deprecated(CONTENT_TYPE + " precision_step parameter is deprecated and will be removed " + "in the next major release"); builder.precisionStep(XContentMapValues.nodeIntegerValue(propNode)); iterator.remove(); } else if (propName.equals("geohash")) { builder.enableGeoHash(XContentMapValues.nodeBooleanValue(propNode)); iterator.remove(); } else if (propName.equals("geohash_prefix")) { builder.geoHashPrefix(XContentMapValues.nodeBooleanValue(propNode)); if (XContentMapValues.nodeBooleanValue(propNode)) { builder.enableGeoHash(true); } iterator.remove(); } else if (propName.equals("geohash_precision")) { if (propNode instanceof Integer) { builder.geoHashPrecision(XContentMapValues.nodeIntegerValue(propNode)); } else { builder.geoHashPrecision(GeoUtils.geoHashLevelsForPrecision(propNode.toString())); } iterator.remove(); } else if (propName.equals(Names.IGNORE_MALFORMED)) { builder.ignoreMalformed(XContentMapValues.nodeBooleanValue(propNode)); iterator.remove(); } else if (parseMultiField(builder, name, parserContext, propName, propNode)) { iterator.remove(); } } if (builder instanceof GeoPointFieldMapperLegacy.Builder) { return GeoPointFieldMapperLegacy.parse((GeoPointFieldMapperLegacy.Builder) builder, node, parserContext); } return (GeoPointFieldMapper.Builder) builder; }
Example 18
Source File: ObjectMapper.java From Elasticsearch with Apache License 2.0 | 4 votes |
public T add(Mapper.Builder builder) { mappersBuilders.add(builder); return this.builder; }
Example 19
Source File: StringFieldMapper.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { StringFieldMapper.Builder builder = stringField(name); parseTextField(builder, name, node, parserContext); for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = iterator.next(); String propName = Strings.toUnderscoreCase(entry.getKey()); Object propNode = entry.getValue(); if (propName.equals("null_value")) { if (propNode == null) { throw new MapperParsingException("Property [null_value] cannot be null."); } builder.nullValue(propNode.toString()); iterator.remove(); } else if (propName.equals("search_quote_analyzer")) { NamedAnalyzer analyzer = parserContext.analysisService().analyzer(propNode.toString()); if (analyzer == null) { throw new MapperParsingException("Analyzer [" + propNode.toString() + "] not found for field [" + name + "]"); } builder.searchQuotedAnalyzer(analyzer); iterator.remove(); } else if (propName.equals("position_increment_gap") || parserContext.indexVersionCreated().before(Version.V_2_0_0) && propName.equals("position_offset_gap")) { int newPositionIncrementGap = XContentMapValues.nodeIntegerValue(propNode, -1); if (newPositionIncrementGap < 0) { throw new MapperParsingException("positions_increment_gap less than 0 aren't allowed."); } builder.positionIncrementGap(newPositionIncrementGap); // we need to update to actual analyzers if they are not set in this case... // so we can inject the position increment gap... if (builder.fieldType().indexAnalyzer() == null) { builder.fieldType().setIndexAnalyzer(parserContext.analysisService().defaultIndexAnalyzer()); } if (builder.fieldType().searchAnalyzer() == null) { builder.fieldType().setSearchAnalyzer(parserContext.analysisService().defaultSearchAnalyzer()); } if (builder.fieldType().searchQuoteAnalyzer() == null) { builder.fieldType().setSearchQuoteAnalyzer(parserContext.analysisService().defaultSearchQuoteAnalyzer()); } iterator.remove(); } else if (propName.equals("ignore_above")) { builder.ignoreAbove(XContentMapValues.nodeIntegerValue(propNode, -1)); iterator.remove(); } else if (parseMultiField(builder, name, parserContext, propName, propNode)) { iterator.remove(); } } return builder; }
Example 20
Source File: GeoPointFieldMapper.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public Mapper.Builder<?, ?> parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException { return super.parse(name, node, parserContext); }