This is a compilation of JANUSGRAPH v0.4.0 learning practices, which will continue to be updated at the end of this article.

If you have a new problem, please leave a comment below.

E01.gremlin is available on the command line, but not by running the Java program in the IDE

Background: It has been implemented in the background to add some vertex data using addV(), the background console can look up, but execute the following code output is ~0.

Code sample

public static void main(String[] args) throws Exception {
        GraphTraversalSource graph = traversal()
                .withRemote(DriverRemoteConnection.using("my.host.com".8182."g"));
      
        List<Vertex> ls = graph.V().has("name").toList();
        System.out.println("= = ="+graph.V().count().next());
        System.out.println("= = ="+graph.getGraph());
        for(Vertex v :ls){
            System.out.println("= = = = = = = = ="+v.label()+"= = = = = = =");
        }
        graph.close();
}
Copy the code

The solution

After adding vertex data to the Gremlin console, it is not found in the Java program and the result is empty because any graph operation automatically starts a transaction. If the transaction is not committed, the action will not take effect. The gremlin console performs the transaction commit to query:

for (tx in graph.getOpenTransactions()) tx.commit()
Copy the code

After the transaction commits, the data just added can be queried in the Java program. Graph.tx ().commit()


E02. Remote connection to GremlinServer, error reported source [g] alias is not configured on the server

Error: The traversal source [g] for alias [g] is not configured on The server

Code sample

As above, it is said that ES does not run properly and also encounters this error.

The solution

Modifying a Configuration File

vim janusgraph-hbase-es.properties
Copy the code

Add the following configuration at the end of the file:

gremlin.graph=org.janusgraph.core.JanusGraphFactory
Copy the code

Save the Settings and restart the GremlinServer

/ path_to_janus janusgraph - 0.4.0 - hadoop2 / bin/gremlin - server. Sh stop/path_to_janus/conf/janusgraph - hbase - es. Properties / path_to_janus janusgraph - 0.4.0 - hadoop2 / bin/gremlin - server. Sh start/path_to_janus/conf/janusgraph - hbase - es. PropertiesCopy the code

Java program can connect to GremlinServer remotely, query data is correct.

E03. java.lang.IllegalArgumentException: Could not instantiate implementation: org.janusgraph.diskstorage.es.ElasticSearchIndex

Error message: under Caused by: Java. Lang. Reflect. InvocationTargetException

The Gremlin command line to create graph times wrong Java. Lang. IllegalArgumentException: Could not instantiate implementation: org.janusgraph.diskstorage.es.ElasticSearchIndex

Note: This error is also reported when using Java code to access the JanusGraph in the IDEA project. The error is not the same as in the E06 project. The investigation is as follows:

Examples of code to execute

gremlin> graph = JanusGraphFactory.open('/opt/janusgraph/conf/janusgraph-hbase-es.properties')
Copy the code

The solution

The results of curl http://localhost:9200 were normal. However, no matter how you modify the HttpClient dependency package, an error is reported. The status of elasticSearch is red (due to server power failure last night). Restore es status to Green and execute code again. The subsequent reading of the data with Java code is fine.

You can see: StandardJanusgraph blah blah…

It took a long time, but we finally solved it. [2019-09-15]

JanusGraph Problems and Solutions series of contents:

JanusGraph Problem Notes – (a) table of Contents

JanusGraph Problem Note (2) : SchemaViolationException

JanusGraph Problem Notes (3) : NoNodeException (hbase)

ResponseException (ES)

JanusGraph Question Note (5) : Did local configuration changes not take effect?


Related columns:

JanusGraph first lesson: Create IDEA project