Janusgraph : Migrating from Neo4j. Issues

207 views
Skip to first unread message

nodechef

unread,
Nov 1, 2018, 4:25:09 AM11/1/18
to JanusGraph users
Hi everyone, We are shifting from neo4j to Janusgraph and I've successfully installed Janusgraph server (https://docs.janusgraph.org/latest/server.html#server-getting-started). This automatically starts the Elasticsearch(ES) instance as well. So my query is is it possible to apply ES on particular node just like in Neo4j where we just add information in following format in neo4j.conf file:


elasticsearch.host_name=http://localhost:9200
elasticsearch.index_spec=people:Person(first_name,last_name), places:Place(name)
Message has been deleted

nodechef

unread,
Nov 1, 2018, 4:29:24 AM11/1/18
to JanusGraph users
Suppose that we keep nodes in our Neo4j instance labeled Person and Place, and that we want to index the values of the first_name and last_name properties of the former and name of the latter in two separate ElasticSearch indices named people and places. For that, we would add the following directives to conf/neo4j.conf

elasticsearch.host_name=http://localhost:9200
elasticsearch.index_spec=people:Person(first_name,last_name), places:Place(name)

Florian Hockmann

unread,
Nov 1, 2018, 6:52:02 AM11/1/18
to JanusGraph users
I don't know Neo4j really, but it looks somewhat similar to how it works with JanusGraph. You basically have to define a schema for JanusGraph which also contains your indices. If you want to use ElasticSearch as an index backend for a particular property, then you have to create a mixed index for that which uses ElasticSearch as the index backend.

For string based indices, you have to decide whether you want to do full-text search, string search or both. Full-text search means that your strings are tokenized which usually means that they are split into words. you can then search for individual tokens, or words. This makes sense if you want to index whole texts. String search on the other hand means that the strings are indexed as is which allows you to match on the whole string, opposed to just its words. Since first name and last name are probably mostly just single "words", string search seems to be the better choice here. You can crate a schema for your Person vertices like this:

mgmt = graph.openManagement()
person = mgmt.makeVertexLabel('Person').make()
firstName = mgmt.makePropertyKey('first_name').dataType(String.class).make()
lastName = mgmt.makePropertyKey('last_name').dataType(String.class).make()
mgmt.buildIndex('personsByFirstName', Vertex.class).addKey(firstName, Mapping.STRING.asParameter()).indexOnly(person).buildMixedIndex("search")
mgmt.buildIndex('personsByLastName', Vertex.class).addKey(lastName, Mapping.STRING.asParameter()).indexOnly(person).buildMixedIndex("search")
mgmt.commit()

This allows you to do traversals that search for examples for all persons whose first name begins with a certain string:

g.V().has('Person', 'first_name', textPrefix('nodech'))

or matches a certain regular expression:

g.V().has('Person', 'first_name', textRegex('.*ode.*')
Reply all
Reply to author
Forward
0 new messages