Search in sources :

Example 1 with IndexMapping

use of org.janusgraph.diskstorage.es.mapping.IndexMapping in project janusgraph by JanusGraph.

the class ElasticSearchIndex method register.

@Override
public void register(String store, String key, KeyInformation information, BaseTransaction tx) throws BackendException {
    final Class<?> dataType = information.getDataType();
    final Mapping map = Mapping.getMapping(information);
    Preconditions.checkArgument(map == Mapping.DEFAULT || AttributeUtils.isString(dataType) || (map == Mapping.PREFIX_TREE && AttributeUtils.isGeo(dataType)), "Specified illegal mapping [%s] for data type [%s]", map, dataType);
    final String indexStoreName = getIndexStoreName(store);
    if (useExternalMappings) {
        try {
            // We check if the externalMapping have the property 'key'
            final IndexMapping mappings = client.getMapping(indexStoreName, store);
            if (mappings == null || (!mappings.isDynamic() && !mappings.getProperties().containsKey(key))) {
                // Error if it is not dynamic and have not the property 'key'
                throw new PermanentBackendException("The external mapping for index '" + indexStoreName + "' and type '" + store + "' do not have property '" + key + "'");
            } else if (allowMappingUpdate && mappings.isDynamic()) {
                // If it is dynamic, we push the unknown property 'key'
                this.pushMapping(store, key, information);
            }
        } catch (final IOException e) {
            throw new PermanentBackendException(e);
        }
    } else {
        try {
            checkForOrCreateIndex(indexStoreName);
        } catch (final IOException e) {
            throw new PermanentBackendException(e);
        }
        this.pushMapping(store, key, information);
    }
}
Also used : IndexMapping(org.janusgraph.diskstorage.es.mapping.IndexMapping) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) Mapping(org.janusgraph.core.schema.Mapping) IndexMapping(org.janusgraph.diskstorage.es.mapping.IndexMapping) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Mapping (org.janusgraph.core.schema.Mapping)1 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)1 IndexMapping (org.janusgraph.diskstorage.es.mapping.IndexMapping)1