From ec84dc7e78d1dcd9476f00e14abff7a9d026c198 Mon Sep 17 00:00:00 2001 From: sjudeng Date: Sun, 11 Feb 2018 10:37:15 -0600 Subject: [PATCH] Always re-read layer attributes --- .../data/elasticsearch/ElasticDataStore.java | 86 +++++++++---------- 1 file changed, 40 insertions(+), 46 deletions(-) diff --git a/gt-elasticsearch/src/main/java/mil/nga/giat/data/elasticsearch/ElasticDataStore.java b/gt-elasticsearch/src/main/java/mil/nga/giat/data/elasticsearch/ElasticDataStore.java index ea24492..a7ce9ae 100644 --- a/gt-elasticsearch/src/main/java/mil/nga/giat/data/elasticsearch/ElasticDataStore.java +++ b/gt-elasticsearch/src/main/java/mil/nga/giat/data/elasticsearch/ElasticDataStore.java @@ -143,57 +143,51 @@ public ContentFeatureSource getFeatureSource(Name name, Transaction tx) } public List getElasticAttributes(Name layerName) throws IOException { - final String localPart = layerName.getLocalPart(); - final ElasticLayerConfiguration layerConfig = layerConfigurations.get(localPart); - final List elasticAttributes; - if (layerConfig == null || layerConfig.getAttributes().isEmpty()) { - final String docType; - if (docTypes.containsKey(layerName)) { - docType = docTypes.get(layerName); - } else { - docType = localPart; - } + final String docType; + if (docTypes.containsKey(layerName)) { + docType = docTypes.get(layerName); + } else { + docType = layerName.getLocalPart(); + } - final Map mapping = getClient().getMapping(indexName, docType); - elasticAttributes = new ArrayList(); - if (mapping != null) { - add(elasticAttributes, "_id", "string", mapping, false); - add(elasticAttributes, "_index", "string", mapping, false); - add(elasticAttributes, "_type", "string", mapping, false); - add(elasticAttributes, "_score", "float", mapping, false); - add(elasticAttributes, "_relative_score", "float", mapping, false); - add(elasticAttributes, "_aggregation", "binary", mapping, false); - - walk(elasticAttributes, mapping, "", false, false); - - // add default geometry and short name and count duplicate short names - final Map counts = new HashMap<>(); - boolean foundGeometry = false; - for (final ElasticAttribute attribute : elasticAttributes) { - if (!foundGeometry && Geometry.class.isAssignableFrom(attribute.getType())) { - attribute.setDefaultGeometry(true); - foundGeometry = true; - } - final String[] parts = attribute.getName().split("\\."); - attribute.setShortName(parts[parts.length-1]); - final int count; - if (counts.containsKey(attribute.getShortName())) { - count = counts.get(attribute.getShortName())+1; - } else { - count = 1; - } - counts.put(attribute.getShortName(), count); + final Map mapping = getClient().getMapping(indexName, docType); + final List elasticAttributes = new ArrayList(); + if (mapping != null) { + add(elasticAttributes, "_id", "string", mapping, false); + add(elasticAttributes, "_index", "string", mapping, false); + add(elasticAttributes, "_type", "string", mapping, false); + add(elasticAttributes, "_score", "float", mapping, false); + add(elasticAttributes, "_relative_score", "float", mapping, false); + add(elasticAttributes, "_aggregation", "binary", mapping, false); + + walk(elasticAttributes, mapping, "", false, false); + + // add default geometry and short name and count duplicate short names + final Map counts = new HashMap<>(); + boolean foundGeometry = false; + for (final ElasticAttribute attribute : elasticAttributes) { + if (!foundGeometry && Geometry.class.isAssignableFrom(attribute.getType())) { + attribute.setDefaultGeometry(true); + foundGeometry = true; } - // use full name if short name has duplicates - for (final ElasticAttribute attribute : elasticAttributes) { - if (counts.get(attribute.getShortName()) > 1) { - attribute.setShortName(attribute.getName()); - } + final String[] parts = attribute.getName().split("\\."); + attribute.setShortName(parts[parts.length-1]); + final int count; + if (counts.containsKey(attribute.getShortName())) { + count = counts.get(attribute.getShortName())+1; + } else { + count = 1; + } + counts.put(attribute.getShortName(), count); + } + // use full name if short name has duplicates + for (final ElasticAttribute attribute : elasticAttributes) { + if (counts.get(attribute.getShortName()) > 1) { + attribute.setShortName(attribute.getName()); } } - } else { - elasticAttributes = layerConfig.getAttributes(); } + return elasticAttributes; }