2017-05-12 31 views
0

我已經在cassandra中存儲了一個titan圖形。以下是代碼。如何索引cassandra中存在的Titan圖形到solr

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中索引相同的圖表有什麼方法?

回答

1

泰坦直接與solr整合。這意味着從來沒有直接談到solr。相反,你讓泰坦與你交談,而且這種情況自然會在遍歷圖時自然發生。

您只需要按照定義的here設置索引。我提供了一個使用Solr/Elastic搜索here優化的混合索引的示例。

所以在上面的例子中,只要你執行一個特定類型的遍歷,titan和solr一起就會快速響應。

只記得你必須創建一個混合索引。

除了定義索引,你還必須得到泰坦與solr運行。不幸的是,這並不是那麼簡單。你必須得到solr運行,然後讓泰坦跟solr說話,因爲我已經做了here

+0

嘿,我跟着你指出的東西。我複製了$ 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」,「http://192.168.2.189:8983/solr」); –

+0

但我得到了:java.lang.ClassNotFoundException:com.thinkaurelius.titan.diskstorage.es.ElasticSearchIndex。我不想使用ES,但只有Cassandra用於存儲,Solr用於索引。你可以分享一個示例代碼嗎? –