简体   繁体   中英

How to index Titan graph present in cassandra to solr

I have stored a titan graph in cassandra. Below is the code.

public class Example1 {

public static void main(String[] args) {
    //Initliase graph
    BaseConfiguration baseConfiguration = new BaseConfiguration();
    baseConfiguration.setProperty("storage.backend", "cassandra");
    baseConfiguration.setProperty("storage.hostname", "192.168.3.82");
    baseConfiguration.setProperty("storage.cassandra.keyspace", "mycustomerdata");
    TitanGraph graph = TitanFactory.open(baseConfiguration);

    //---------------- Adding Data -------------------
    //Create some customers
    Vertex alice = graph.addVertex("customer");
    alice.property("name", "Alice Mc Alice");
    alice.property("birthdat", "100000 BC");

    Vertex bob = graph.addVertex("customer");
    bob.property("name", "Bob Mc Bob");
    bob.property("birthdat", "1000 BC");

    //Create Some Products
    Vertex meat = graph.addVertex("product");
    meat.property("name", "Meat");
    meat.property("description", "Delicious Meat");

    Vertex lettuce = graph.addVertex("product");
    lettuce.property("name", "Lettuce");
    lettuce.property("description", "Delicious Lettuce which is green");

    //Alice Bought some meat:
    alice.addEdge("bought", meat);
    //Bob Bought some meat and lettuce:
    bob.addEdge("bought",lettuce);

    //---------------- Querying (aka traversing whcih is what you do in graph dbs) Data -------------------
    //Now who has bought meat?
    graph.traversal().V().has("name", "meat").in("bought").forEachRemaining(v -> System.out.println(v.value("name")));

    //Who are all our customers
    /*graph.traversal().V().hasLabel("customer").forEachRemaining(v -> System.out.println(v.value("name")));

    //What products do we have
    graph.traversal().V().hasLabel("product").forEachRemaining(v -> System.out.println(v.value("name")));*/


    graph.close();

}
}

I would like index the same graph in solr .

  1. How to do this in using java ?
  2. Do I have query the tables of the keyspace and index ? what's the approach for having the same graph indexed in solr ?

Titan integrates directly with solr. Which means that you never have to talk to solr directly. Rather, you let titan talk with it for you and this happens naturally whenever traversing the graph.

All you have to do is setup your indexing as defined here . I provide an example of using a Mixed index optimised by Solr/Elastic search here .

So in the above example whenever you execute a specific type of traversals titan together with solr will respond quickly.

Just remember you have to create a Mixed Index.

In addition to defining the indices you also have to get titan running with solr. Unfortunately this is not so simple. You have to get solr running and then get titan talking to solr as I have done here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM