【问题标题】:How to index Titan graph present in cassandra to solr如何将cassandra中存在的Titan图索引到solr
【发布时间】:2025-10-22 17:45:02
【问题描述】:

我在 cassandra 中存储了一张泰坦图。下面是代码。

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();

}
}

我想在 solr 中索引相同的图表。

  1. 在使用 java 时如何做到这一点?
  2. 我有查询键空间和索引的表吗?在 solr 中索引相同图表的方法是什么?

【问题讨论】:

    标签: java graph solr cassandra titan


    【解决方案1】:

    Titan 直接与 solr 集成。这意味着 永远不必直接与 solr 交谈。相反,你让 Titan 替你说话,这在遍历图表时自然而然地发生。

    您所要做的就是按照here 的定义设置索引。我提供了一个使用由 Solr/Elastic 搜索 here 优化的混合索引的示例。

    所以在上面的例子中,每当你执行特定类型的遍历时,titan 和 solr 都会快速响应。

    请记住,您必须创建一个混合索引。

    除了定义索引之外,您还必须让 Titan 使用 solr 运行。不幸的是,这并不是那么简单。你必须让 solr 运行,然后让 Titan 与 solr 交谈,就像我所做的那样 here

    【讨论】:

    • 嘿,我按照您指出的内容进行操作。我已经复制了 $SOLR_HOME/server/solr/configsets/{config_set} 下的 titan/conf/solr 的内容,包括子目录。我还没有在 Solr 中创建任何核心,但是使配置代码看起来像这样 BaseConfiguration baseConfiguration = new BaseConfiguration(); baseConfiguration.setProperty("index.search.backend", "solr"); baseConfiguration.setProperty("index.search.solr.mode", "http"); baseConfiguration.setProperty("index.search.solr.httpurls","192.168.2.189:8983/solr");
    • 但我得到了原因:java.lang.ClassNotFoundException: com.thinkaurelius.titan.diskstorage.es.ElasticSearchIndex。我不想使用 ES,而只想使用 Cassandra 进行存储,使用 Solr 进行索引。你能分享一个示例代码吗