Search in sources :

Example 1 with TypeReference

use of org.apache.tinkerpop.shaded.jackson.core.type.TypeReference in project janusgraph by JanusGraph.

the class ElasticSearchConfigTest method readMapping.

private IndexMappings readMapping(final ElasticMajorVersion version, final String mappingFilePath) throws IOException {
    try (final InputStream inputStream = getClass().getResourceAsStream(mappingFilePath)) {
        final IndexMappings mappings = objectMapper.readValue(inputStream, new TypeReference<IndexMappings>() {
        });
        if (version.getValue() < 5) {
            // downgrade from text to string and keyword to string/not-analyzed
            mappings.getMappings().values().stream().flatMap(mapping -> mapping.getProperties().entrySet().stream()).map(entry -> (Map<String, Object>) entry.getValue()).forEach(properties -> {
                if (properties.get("type").equals("keyword")) {
                    properties.put("type", "string");
                    properties.put("index", "not_analyzed");
                } else if (properties.get("type").equals("text")) {
                    properties.put("type", "string");
                }
            });
        }
        return mappings;
    }
}
Also used : StandardBaseTransactionConfig(org.janusgraph.diskstorage.util.StandardBaseTransactionConfig) PredicateCondition(org.janusgraph.graphdb.query.condition.PredicateCondition) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) INDEX_HOSTS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.INDEX_HOSTS) EntityUtils(org.apache.http.util.EntityUtils) InetAddress(java.net.InetAddress) HttpDelete(org.apache.http.client.methods.HttpDelete) Charset(java.nio.charset.Charset) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) After(org.junit.After) Duration(java.time.Duration) Map(java.util.Map) TypeReference(org.apache.tinkerpop.shaded.jackson.core.type.TypeReference) BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) Before(org.junit.Before) BackendException(org.janusgraph.diskstorage.BackendException) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ImmutableMap(com.google.common.collect.ImmutableMap) JanusGraphFactory(org.janusgraph.core.JanusGraphFactory) Configuration(org.janusgraph.diskstorage.configuration.Configuration) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) org.janusgraph.diskstorage.indexing(org.janusgraph.diskstorage.indexing) StringEntity(org.apache.http.entity.StringEntity) Test(org.junit.Test) IOException(java.io.IOException) JanusGraph(org.janusgraph.core.JanusGraph) ElasticSearchIndex(org.janusgraph.diskstorage.es.ElasticSearchIndex) IOUtils(org.apache.commons.io.IOUtils) IndexMappings(org.janusgraph.diskstorage.es.IndexMappings) HttpPut(org.apache.http.client.methods.HttpPut) Text(org.janusgraph.core.attribute.Text) BaseTransactionConfig(org.janusgraph.diskstorage.BaseTransactionConfig) TimestampProviders(org.janusgraph.diskstorage.util.time.TimestampProviders) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) Entry(java.util.Map.Entry) BasicConfiguration(org.janusgraph.diskstorage.configuration.BasicConfiguration) Assert(org.junit.Assert) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) HttpHost(org.apache.http.HttpHost) HttpClients(org.apache.http.impl.client.HttpClients) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) InputStream(java.io.InputStream) IndexMappings(org.janusgraph.diskstorage.es.IndexMappings) InputStream(java.io.InputStream) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InetAddress (java.net.InetAddress)1 Charset (java.nio.charset.Charset)1 Duration (java.time.Duration)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)1 IOUtils (org.apache.commons.io.IOUtils)1 HttpHost (org.apache.http.HttpHost)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpDelete (org.apache.http.client.methods.HttpDelete)1 HttpPut (org.apache.http.client.methods.HttpPut)1 HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)1 StringEntity (org.apache.http.entity.StringEntity)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 HttpClients (org.apache.http.impl.client.HttpClients)1 EntityUtils (org.apache.http.util.EntityUtils)1 TypeReference (org.apache.tinkerpop.shaded.jackson.core.type.TypeReference)1