diff --git a/plugins/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpProcessor.java b/plugins/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpProcessor.java index 2f8d1038f8d8..96902f852a16 100644 --- a/plugins/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpProcessor.java +++ b/plugins/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpProcessor.java @@ -57,8 +57,8 @@ public final class GeoIpProcessor extends AbstractProcessor { public static final String TYPE = "geoip"; - private static final String CITY_DB_TYPE = "GeoLite2-City"; - private static final String COUNTRY_DB_TYPE = "GeoLite2-Country"; + private static final String CITY_DB_SUFFIX = "-City"; + private static final String COUNTRY_DB_SUFFIX = "-Country"; private final String field; private final String targetField; @@ -93,24 +93,23 @@ public void execute(IngestDocument ingestDocument) { final InetAddress ipAddress = InetAddresses.forString(ip); Map geoData; - switch (dbReader.getMetadata().getDatabaseType()) { - case CITY_DB_TYPE: - try { - geoData = retrieveCityGeoData(ipAddress); - } catch (AddressNotFoundRuntimeException e) { - geoData = Collections.emptyMap(); - } - break; - case COUNTRY_DB_TYPE: - try { - geoData = retrieveCountryGeoData(ipAddress); - } catch (AddressNotFoundRuntimeException e) { - geoData = Collections.emptyMap(); - } - break; - default: - throw new ElasticsearchParseException("Unsupported database type [" + dbReader.getMetadata().getDatabaseType() - + "]", new IllegalStateException()); + String databaseType = dbReader.getMetadata().getDatabaseType(); + + if (databaseType.endsWith(CITY_DB_SUFFIX)) { + try { + geoData = retrieveCityGeoData(ipAddress); + } catch (AddressNotFoundRuntimeException e) { + geoData = Collections.emptyMap(); + } + } else if (databaseType.endsWith(COUNTRY_DB_SUFFIX)) { + try { + geoData = retrieveCountryGeoData(ipAddress); + } catch (AddressNotFoundRuntimeException e) { + geoData = Collections.emptyMap(); + } + } else { + throw new ElasticsearchParseException("Unsupported database type [" + dbReader.getMetadata().getDatabaseType() + + "]", new IllegalStateException()); } if (geoData.isEmpty() == false) { ingestDocument.setFieldValue(targetField, geoData); @@ -305,9 +304,9 @@ public GeoIpProcessor create(Map registry, String pro } } } else { - if (CITY_DB_TYPE.equals(databaseType)) { + if (databaseType.endsWith(CITY_DB_SUFFIX)) { properties = DEFAULT_CITY_PROPERTIES; - } else if (COUNTRY_DB_TYPE.equals(databaseType)) { + } else if (databaseType.endsWith(COUNTRY_DB_SUFFIX)) { properties = DEFAULT_COUNTRY_PROPERTIES; } else { throw newConfigurationException(TYPE, processorTag, "database_file", "Unsupported database type [" @@ -346,9 +345,9 @@ enum Property { public static Property parseProperty(String databaseType, String value) { Set validProperties = EnumSet.noneOf(Property.class); - if (CITY_DB_TYPE.equals(databaseType)) { + if (databaseType.endsWith(CITY_DB_SUFFIX)) { validProperties = ALL_CITY_PROPERTIES; - } else if (COUNTRY_DB_TYPE.equals(databaseType)) { + } else if (databaseType.endsWith(COUNTRY_DB_SUFFIX)) { validProperties = ALL_COUNTRY_PROPERTIES; }