Search in sources :

Example 1 with ElasticSearchIndex

use of org.janusgraph.diskstorage.es.ElasticSearchIndex in project janusgraph by JanusGraph.

the class ElasticSearchConfigTest method testExternalDynamic.

@Test
public void testExternalDynamic() throws Exception {
    final Duration maxWrite = Duration.ofMillis(2000L);
    final String storeName = "test_mapping";
    final Configuration indexConfig = GraphDatabaseConfiguration.buildGraphConfiguration().set(USE_EXTERNAL_MAPPINGS, true, INDEX_NAME).restrictTo(INDEX_NAME);
    final IndexProvider idx = open(indexConfig);
    final ElasticMajorVersion version = ((ElasticSearchIndex) idx).getVersion();
    // Test create index KO mapping is not push
    final KeyInformation.IndexRetriever indexRetriever = IndexProviderTest.getIndexRetriever(IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD));
    final BaseTransactionConfig txConfig = StandardBaseTransactionConfig.of(TimestampProviders.MILLI);
    final IndexTransaction itx = new IndexTransaction(idx, indexRetriever, txConfig, maxWrite);
    try {
        idx.register(storeName, "date", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("date"), itx);
        fail("should fail");
    } catch (final PermanentBackendException ignored) {
    }
    final HttpPut newMapping = new HttpPut("janusgraph_" + storeName);
    newMapping.setEntity(new StringEntity(objectMapper.writeValueAsString(readMapping(version, "/dynamic_mapping.json")), Charset.forName("UTF-8")));
    executeRequest(newMapping);
    // Test date property OK
    idx.register(storeName, "date", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("date"), itx);
    // Test weight property OK  because dynamic mapping
    idx.register(storeName, "weight", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("weight"), itx);
    itx.rollback();
    idx.close();
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) Configuration(org.janusgraph.diskstorage.configuration.Configuration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) BasicConfiguration(org.janusgraph.diskstorage.configuration.BasicConfiguration) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) Duration(java.time.Duration) StandardBaseTransactionConfig(org.janusgraph.diskstorage.util.StandardBaseTransactionConfig) BaseTransactionConfig(org.janusgraph.diskstorage.BaseTransactionConfig) HttpPut(org.apache.http.client.methods.HttpPut) StringEntity(org.apache.http.entity.StringEntity) ElasticSearchIndex(org.janusgraph.diskstorage.es.ElasticSearchIndex) Test(org.junit.Test)

Example 2 with ElasticSearchIndex

use of org.janusgraph.diskstorage.es.ElasticSearchIndex in project janusgraph by JanusGraph.

the class ElasticSearchConfigTest method testExternalMappingsViaTemplate.

@Test
public void testExternalMappingsViaTemplate() throws Exception {
    final Duration maxWrite = Duration.ofMillis(2000L);
    final String storeName = "test_mapping";
    final Configuration indexConfig = GraphDatabaseConfiguration.buildGraphConfiguration().set(USE_EXTERNAL_MAPPINGS, true, INDEX_NAME).restrictTo(INDEX_NAME);
    final IndexProvider idx = open(indexConfig);
    final ElasticMajorVersion version = ((ElasticSearchIndex) idx).getVersion();
    final HttpPut newTemplate = new HttpPut("_template/template_1");
    final Map<String, Object> content = ImmutableMap.of("template", "janusgraph_test_mapping*", "mappings", readMapping(version, "/strict_mapping.json").getMappings());
    newTemplate.setEntity(new StringEntity(objectMapper.writeValueAsString(content), Charset.forName("UTF-8")));
    executeRequest(newTemplate);
    final HttpPut newMapping = new HttpPut("janusgraph_" + storeName);
    executeRequest(newMapping);
    final KeyInformation.IndexRetriever indexRetriever = IndexProviderTest.getIndexRetriever(IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD));
    final BaseTransactionConfig txConfig = StandardBaseTransactionConfig.of(TimestampProviders.MILLI);
    final IndexTransaction itx = new IndexTransaction(idx, indexRetriever, txConfig, maxWrite);
    // Test date property OK
    idx.register(storeName, "date", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("date"), itx);
    // Test weight property KO
    try {
        idx.register(storeName, "weight", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("weight"), itx);
        fail("should fail");
    } catch (final BackendException ignored) {
    }
    itx.rollback();
    idx.close();
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) Configuration(org.janusgraph.diskstorage.configuration.Configuration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) BasicConfiguration(org.janusgraph.diskstorage.configuration.BasicConfiguration) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) Duration(java.time.Duration) StandardBaseTransactionConfig(org.janusgraph.diskstorage.util.StandardBaseTransactionConfig) BaseTransactionConfig(org.janusgraph.diskstorage.BaseTransactionConfig) HttpPut(org.apache.http.client.methods.HttpPut) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) StringEntity(org.apache.http.entity.StringEntity) ElasticSearchIndex(org.janusgraph.diskstorage.es.ElasticSearchIndex) Test(org.junit.Test)

Example 3 with ElasticSearchIndex

use of org.janusgraph.diskstorage.es.ElasticSearchIndex in project janusgraph by JanusGraph.

the class ElasticSearchConfigTest method open.

private IndexProvider open(Configuration indexConfig) throws BackendException {
    final ElasticSearchIndex idx = new ElasticSearchIndex(indexConfig);
    idx.clearStorage();
    idx.close();
    return new ElasticSearchIndex(indexConfig);
}
Also used : ElasticSearchIndex(org.janusgraph.diskstorage.es.ElasticSearchIndex)

Example 4 with ElasticSearchIndex

use of org.janusgraph.diskstorage.es.ElasticSearchIndex in project janusgraph by JanusGraph.

the class ElasticSearchConfigTest method testClient.

@Test
public void testClient() throws BackendException, InterruptedException {
    final ModifiableConfiguration config = esr.setElasticsearchConfiguration(GraphDatabaseConfiguration.buildGraphConfiguration(), INDEX_NAME);
    Configuration indexConfig = config.restrictTo(INDEX_NAME);
    IndexProvider idx = open(indexConfig);
    simpleWriteAndQuery(idx);
    idx.close();
    config.set(INDEX_HOSTS, new String[] { "10.11.12.13:" + ElasticsearchRunner.PORT }, INDEX_NAME);
    indexConfig = config.restrictTo(INDEX_NAME);
    Throwable failure = null;
    try {
        new ElasticSearchIndex(indexConfig);
    } catch (final Throwable t) {
        failure = t;
    }
    Assert.assertNotNull("ES client failed to throw exception on connection failure", failure);
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) Configuration(org.janusgraph.diskstorage.configuration.Configuration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) BasicConfiguration(org.janusgraph.diskstorage.configuration.BasicConfiguration) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) ElasticSearchIndex(org.janusgraph.diskstorage.es.ElasticSearchIndex) Test(org.junit.Test)

Example 5 with ElasticSearchIndex

use of org.janusgraph.diskstorage.es.ElasticSearchIndex in project janusgraph by JanusGraph.

the class ElasticSearchConfigTest method testExternalMappingsViaMapping.

@Test
public void testExternalMappingsViaMapping() throws Exception {
    final Duration maxWrite = Duration.ofMillis(2000L);
    final String storeName = "test_mapping";
    final Configuration indexConfig = GraphDatabaseConfiguration.buildGraphConfiguration().set(USE_EXTERNAL_MAPPINGS, true, INDEX_NAME).restrictTo(INDEX_NAME);
    final IndexProvider idx = open(indexConfig);
    final ElasticMajorVersion version = ((ElasticSearchIndex) idx).getVersion();
    // Test create index KO mapping is not push
    final KeyInformation.IndexRetriever indexRetriever = IndexProviderTest.getIndexRetriever(IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD));
    final BaseTransactionConfig txConfig = StandardBaseTransactionConfig.of(TimestampProviders.MILLI);
    final IndexTransaction itx = new IndexTransaction(idx, indexRetriever, txConfig, maxWrite);
    try {
        idx.register(storeName, "date", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("date"), itx);
        fail("should fail");
    } catch (final PermanentBackendException ignored) {
    }
    final HttpPut newMapping = new HttpPut("janusgraph_" + storeName);
    newMapping.setEntity(new StringEntity(objectMapper.writeValueAsString(readMapping(version, "/strict_mapping.json")), Charset.forName("UTF-8")));
    executeRequest(newMapping);
    // Test date property OK
    idx.register(storeName, "date", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("date"), itx);
    // Test weight property KO
    try {
        idx.register(storeName, "weight", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("weight"), itx);
        fail("should fail");
    } catch (final BackendException ignored) {
    }
    itx.rollback();
    idx.close();
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) Configuration(org.janusgraph.diskstorage.configuration.Configuration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) BasicConfiguration(org.janusgraph.diskstorage.configuration.BasicConfiguration) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) Duration(java.time.Duration) StandardBaseTransactionConfig(org.janusgraph.diskstorage.util.StandardBaseTransactionConfig) BaseTransactionConfig(org.janusgraph.diskstorage.BaseTransactionConfig) HttpPut(org.apache.http.client.methods.HttpPut) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) StringEntity(org.apache.http.entity.StringEntity) ElasticSearchIndex(org.janusgraph.diskstorage.es.ElasticSearchIndex) Test(org.junit.Test)

Aggregations

ElasticSearchIndex (org.janusgraph.diskstorage.es.ElasticSearchIndex)5 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)4 BasicConfiguration (org.janusgraph.diskstorage.configuration.BasicConfiguration)4 Configuration (org.janusgraph.diskstorage.configuration.Configuration)4 ModifiableConfiguration (org.janusgraph.diskstorage.configuration.ModifiableConfiguration)4 CommonsConfiguration (org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration)4 GraphDatabaseConfiguration (org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration)4 Test (org.junit.Test)4 Duration (java.time.Duration)3 HttpPut (org.apache.http.client.methods.HttpPut)3 StringEntity (org.apache.http.entity.StringEntity)3 BaseTransactionConfig (org.janusgraph.diskstorage.BaseTransactionConfig)3 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)3 StandardBaseTransactionConfig (org.janusgraph.diskstorage.util.StandardBaseTransactionConfig)3 BackendException (org.janusgraph.diskstorage.BackendException)2