Ejemplo n.º 1
0
 public static void parseNumberField(
     NumberFieldMapper.Builder builder,
     String name,
     Map<String, Object> numberNode,
     Mapper.TypeParser.ParserContext parserContext) {
   parseField(builder, name, numberNode, parserContext);
   for (Iterator<Map.Entry<String, Object>> iterator = numberNode.entrySet().iterator();
       iterator.hasNext(); ) {
     Map.Entry<String, Object> entry = iterator.next();
     String propName = Strings.toUnderscoreCase(entry.getKey());
     Object propNode = entry.getValue();
     if (propName.equals("precision_step")) {
       builder.precisionStep(nodeIntegerValue(propNode));
       iterator.remove();
     } else if (propName.equals("ignore_malformed")) {
       builder.ignoreMalformed(nodeBooleanValue(propNode));
       iterator.remove();
     } else if (propName.equals("coerce")) {
       builder.coerce(nodeBooleanValue(propNode));
       iterator.remove();
     } else if (propName.equals("omit_norms")) {
       builder.omitNorms(nodeBooleanValue(propNode));
       iterator.remove();
     } else if (propName.equals("similarity")) {
       builder.similarity(parserContext.similarityLookupService().similarity(propNode.toString()));
       iterator.remove();
     } else if (parseMultiField(builder, name, parserContext, propName, propNode)) {
       iterator.remove();
     }
   }
 }
Ejemplo n.º 2
0
    private static ObjectMapper parseDynamicValue(final ParseContext context, ObjectMapper parentMapper, String currentFieldName, XContentParser.Token token) throws IOException {
        ObjectMapper.Dynamic dynamic = parentMapper.dynamic();
        if (dynamic == null) {
            dynamic = dynamicOrDefault(context.root().dynamic());
        }
        if (dynamic == ObjectMapper.Dynamic.STRICT) {
            throw new StrictDynamicMappingException(parentMapper.fullPath(), currentFieldName);
        }
        if (dynamic == ObjectMapper.Dynamic.FALSE) {
            return null;
        }
        final Mapper.BuilderContext builderContext = new Mapper.BuilderContext(context.indexSettings(), context.path());
        final MappedFieldType existingFieldType = context.mapperService().fullName(context.path().fullPathAsText(currentFieldName));
        Mapper.Builder builder = null;
        if (existingFieldType != null) {
            // create a builder of the same type
            builder = createBuilderFromFieldType(context, existingFieldType, currentFieldName);
            if (builder != null) {
                // best-effort to not introduce a conflict
                if (builder instanceof StringFieldMapper.Builder) {
                    StringFieldMapper.Builder stringBuilder = (StringFieldMapper.Builder) builder;
                    stringBuilder.fieldDataSettings(existingFieldType.fieldDataType().getSettings());
                    stringBuilder.store(existingFieldType.stored());
                    stringBuilder.indexOptions(existingFieldType.indexOptions());
                    stringBuilder.tokenized(existingFieldType.tokenized());
                    stringBuilder.omitNorms(existingFieldType.omitNorms());
                    stringBuilder.docValues(existingFieldType.hasDocValues());
                    stringBuilder.indexAnalyzer(existingFieldType.indexAnalyzer());
                    stringBuilder.searchAnalyzer(existingFieldType.searchAnalyzer());
                } else if (builder instanceof NumberFieldMapper.Builder) {
                    NumberFieldMapper.Builder<?,?> numberBuilder = (NumberFieldMapper.Builder<?, ?>) builder;
                    numberBuilder.fieldDataSettings(existingFieldType.fieldDataType().getSettings());
                    numberBuilder.store(existingFieldType.stored());
                    numberBuilder.indexOptions(existingFieldType.indexOptions());
                    numberBuilder.tokenized(existingFieldType.tokenized());
                    numberBuilder.omitNorms(existingFieldType.omitNorms());
                    numberBuilder.docValues(existingFieldType.hasDocValues());
                    numberBuilder.precisionStep(existingFieldType.numericPrecisionStep());
                }
            }
        }
        if (builder == null) {
            builder = createBuilderFromDynamicValue(context, token, currentFieldName);
        }
        Mapper mapper = builder.build(builderContext);

        mapper = parseAndMergeUpdate(mapper, context);

        ObjectMapper update = null;
        if (mapper != null) {
            update = parentMapper.mappingUpdate(mapper);
        }
        return update;
    }
    @Override
    public GeoPointFieldMapper build(BuilderContext context) {
      ContentPath.Type origPathType = context.path().pathType();
      context.path().pathType(pathType);

      DoubleFieldMapper latMapper = null;
      DoubleFieldMapper lonMapper = null;
      GeoPointFieldType geoPointFieldType = (GeoPointFieldType) fieldType;

      context.path().add(name);
      if (enableLatLon) {
        NumberFieldMapper.Builder<?, ?> latMapperBuilder =
            doubleField(Names.LAT).includeInAll(false);
        NumberFieldMapper.Builder<?, ?> lonMapperBuilder =
            doubleField(Names.LON).includeInAll(false);
        if (precisionStep != null) {
          latMapperBuilder.precisionStep(precisionStep);
          lonMapperBuilder.precisionStep(precisionStep);
        }
        latMapper =
            (DoubleFieldMapper)
                latMapperBuilder
                    .includeInAll(false)
                    .store(fieldType.stored())
                    .docValues(false)
                    .build(context);
        lonMapper =
            (DoubleFieldMapper)
                lonMapperBuilder
                    .includeInAll(false)
                    .store(fieldType.stored())
                    .docValues(false)
                    .build(context);
        geoPointFieldType.setLatLonEnabled(latMapper.fieldType(), lonMapper.fieldType());
      }
      StringFieldMapper geohashMapper = null;
      if (enableGeoHash || enableGeohashPrefix) {
        // TODO: possible also implicitly enable geohash if geohash precision is set
        geohashMapper =
            stringField(Names.GEOHASH)
                .index(true)
                .tokenized(false)
                .includeInAll(false)
                .omitNorms(true)
                .indexOptions(IndexOptions.DOCS)
                .build(context);
        geoPointFieldType.setGeohashEnabled(
            geohashMapper.fieldType(), geoHashPrecision, enableGeohashPrefix);
      }
      context.path().remove();

      context.path().pathType(origPathType);

      // this is important: even if geo points feel like they need to be tokenized to distinguish
      // lat from lon, we actually want to
      // store them as a single token.
      fieldType.setTokenized(false);
      setupFieldType(context);
      fieldType.setHasDocValues(false);
      defaultFieldType.setHasDocValues(false);
      return new GeoPointFieldMapper(
          name,
          fieldType,
          defaultFieldType,
          context.indexSettings(),
          origPathType,
          latMapper,
          lonMapper,
          geohashMapper,
          multiFieldsBuilder.build(this, context));
    }