Java Code Examples for org.elasticsearch.common.xcontent.support.XContentMapValues#nodeBooleanValue()

The following examples show how to use org.elasticsearch.common.xcontent.support.XContentMapValues#nodeBooleanValue() . 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: BaseGeoPointFieldMapper.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@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 2
Source File: GeoPointFieldMapperLegacy.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public static Builder parse(Builder builder, Map<String, Object> node, Mapper.TypeParser.ParserContext parserContext) throws MapperParsingException {
    final boolean indexCreatedBeforeV2_0 = parserContext.indexVersionCreated().before(Version.V_2_0_0);
    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 (indexCreatedBeforeV2_0 && propName.equals("validate")) {
            deprecationLogger.deprecated(CONTENT_TYPE + " validate parameter is deprecated and will be removed "
            + "in the next major release");
            builder.ignoreMalformed = !XContentMapValues.nodeBooleanValue(propNode);
            iterator.remove();
        } else if (indexCreatedBeforeV2_0 && propName.equals("validate_lon")) {
            deprecationLogger.deprecated(CONTENT_TYPE + " validate_lon parameter is deprecated and will be removed "
                + "in the next major release");
            builder.ignoreMalformed = !XContentMapValues.nodeBooleanValue(propNode);
            iterator.remove();
        } else if (indexCreatedBeforeV2_0 && propName.equals("validate_lat")) {
            deprecationLogger.deprecated(CONTENT_TYPE + " validate_lat parameter is deprecated and will be removed "
                + "in the next major release");
            builder.ignoreMalformed = !XContentMapValues.nodeBooleanValue(propNode);
            iterator.remove();
        } else if (propName.equals(Names.COERCE)) {
            builder.coerce = XContentMapValues.nodeBooleanValue(propNode);
            iterator.remove();
        } else if (indexCreatedBeforeV2_0 && propName.equals("normalize")) {
            deprecationLogger.deprecated(CONTENT_TYPE + " normalize parameter is deprecated and will be removed "
                + "in the next major release");
            builder.coerce = XContentMapValues.nodeBooleanValue(propNode);
            iterator.remove();
        } else if (indexCreatedBeforeV2_0 && propName.equals("normalize_lat")) {
            deprecationLogger.deprecated(CONTENT_TYPE + " normalize_lat parameter is deprecated and will be removed "
                + "in the next major release");
            builder.coerce = XContentMapValues.nodeBooleanValue(propNode);
            iterator.remove();
        } else if (indexCreatedBeforeV2_0 && propName.equals("normalize_lon")) {
            deprecationLogger.deprecated(CONTENT_TYPE + " normalize_lon parameter is deprecated and will be removed "
                + "in the next major release");
            builder.coerce = XContentMapValues.nodeBooleanValue(propNode);
            iterator.remove();
        }
    }
    return builder;
}
 
Example 3
Source File: S3River.java    From es-amazon-s3-river with Apache License 2.0 4 votes vote down vote up
@Inject
@SuppressWarnings({ "unchecked" })
protected S3River(RiverName riverName, RiverSettings settings, Client client, ThreadPool threadPool) throws Exception{
   super(riverName, settings);
   this.client = client;
   this.threadPool = threadPool;
   this.riverStatus = RiverStatus.UNKNOWN;
   
   // Deal with connector settings.
   if (settings.settings().containsKey("amazon-s3")){
      Map<String, Object> feed = (Map<String, Object>)settings.settings().get("amazon-s3");
      
      // Retrieve feed settings.
      String feedname = XContentMapValues.nodeStringValue(feed.get("name"), null);
      String bucket = XContentMapValues.nodeStringValue(feed.get("bucket"), null);
      String pathPrefix = XContentMapValues.nodeStringValue(feed.get("pathPrefix"), null);
      String downloadHost = XContentMapValues.nodeStringValue(feed.get("download_host"), null);
      int updateRate = XContentMapValues.nodeIntegerValue(feed.get("update_rate"), 15 * 60 * 1000);
      boolean jsonSupport = XContentMapValues.nodeBooleanValue(feed.get("json_support"), false);
      double indexedCharsRatio  = XContentMapValues.nodeDoubleValue(feed.get("indexed_chars_ratio"), 0.0);
      
      String[] includes = S3RiverUtil.buildArrayFromSettings(settings.settings(), "amazon-s3.includes");
      String[] excludes = S3RiverUtil.buildArrayFromSettings(settings.settings(), "amazon-s3.excludes");
      
      // Retrieve connection settings.
      String accessKey = XContentMapValues.nodeStringValue(feed.get("accessKey"), null);
      String secretKey = XContentMapValues.nodeStringValue(feed.get("secretKey"), null);
      boolean useIAMRoleForEC2 = XContentMapValues.nodeBooleanValue(feed.get("use_EC2_IAM"), false);
      
      feedDefinition = new S3RiverFeedDefinition(feedname, bucket, pathPrefix, downloadHost,
            updateRate, Arrays.asList(includes), Arrays.asList(excludes), accessKey, secretKey, useIAMRoleForEC2,
            jsonSupport, indexedCharsRatio);
   } else {
      logger.error("You didn't define the amazon-s3 settings. Exiting... See https://github.com/lbroudoux/es-amazon-s3-river");
      indexName = null;
      typeName = null;
      bulkSize = 100;
      feedDefinition = null;
      s3 = null;
      return;
   }
   
   // Deal with index settings if provided.
   if (settings.settings().containsKey("index")) {
      Map<String, Object> indexSettings = (Map<String, Object>)settings.settings().get("index");
      
      indexName = XContentMapValues.nodeStringValue(indexSettings.get("index"), riverName.name());
      typeName = XContentMapValues.nodeStringValue(indexSettings.get("type"), S3RiverUtil.INDEX_TYPE_DOC);
      bulkSize = XContentMapValues.nodeIntegerValue(indexSettings.get("bulk_size"), 100);
   } else {
      indexName = riverName.name();
      typeName = S3RiverUtil.INDEX_TYPE_DOC;
      bulkSize = 100;
   }
   
   // We need to connect to Amazon S3 after ensure mandatory settings are here.
   if (feedDefinition.getBucket() == null){
      logger.error("Amazon S3 bucket should not be null. Please fix this.");
      throw new IllegalArgumentException("Amazon S3 bucket should not be null.");
   }
   // Connect using the appropriate authentication process.
   if (feedDefinition.getAccessKey() == null && feedDefinition.getSecretKey() == null) {
      s3 = new S3Connector(feedDefinition.isUseIAMRoleForEC2());
   } else {
      s3 = new S3Connector(feedDefinition.getAccessKey(), feedDefinition.getSecretKey());
   }
   try {
      s3.connectUserBucket(feedDefinition.getBucket(), feedDefinition.getPathPrefix());
   } catch (AmazonS3Exception ase){
      logger.error("Exception while connecting Amazon S3 user bucket. "
            + "Either access key, secret key, IAM Role or bucket name are incorrect");
      throw ase;
   }

   this.riverStatus = RiverStatus.INITIALIZED;
}