【實測】JanusGraph索引配置中的[X]究竟是什麼?

在上一篇JanusGraph建立新圖的文章中,一位熱心同窗提出一個很棒的問題,就是問我索引配置裏官網N次提到的[X]究竟是什麼?本身動手實踐了一番,整理成此文,以期探討。shell

+++++++++++(貼原評):後端

略微一搜:JanusGraph的官網配置文檔裏[X]出現了上百次=>ES配置傳送門bash

權威解釋

Note:JanusGraph’s index options start with the string "index.[X]." where "[X]" is a user-defined name for the backend. This user-defined name must be passed to JanusGraph’s ManagementSystem interface when building a mixed index, as described in Mixed Index, so that JanusGraph knows which of potentially multiple configured index backends to use. Configuration snippets in this chapter use the name search, whereas prose discussion of options typically write [X] in the same position. The exact index name is not significant as long as it is used consistently in JanusGraph’s configuration and when administering indices.elasticsearch

不權威翻譯

注意:JanusGraph的索引選項以字符串「index.[X]」開頭。其中「[X]」是用戶定義名稱的後端暱稱。在構建混合索引(術語:Mixed)時,必須將此用戶定義的名稱傳遞給JanusGraph的ManagementSystem接口,如混合索引中所述,這是爲了JanusGraph知道使用多個已配置的索引後端的哪個。本章中的配置片斷使用名稱爲「search」,而全文對選項的討論一般在同一位置寫入[X]。 只要在JanusGraph的配置中以及管理索引時使用一致的名字,確切的索引名稱就不重要。

實測

【全程實戰】怎麼新建JanusGraph圖並寫入數據?所述的,關鍵的三個[X]是:post

#索引後端
index.search.backend=elasticsearch
# ES服務的節點地址及端口,:9200能夠不寫
index.search.hostname=mhostname1:9200,hostname2:9200,hostname3:9200
# 在ES中的索引別名
index.sanguo.index-name=sanguosha
複製代碼

執行mgmt.buildIndex('age', Vertex.class).addKey(age).buildMixedIndex("sanguo") 這個實測結果在ES裏生成的索引別名是sanguosha學習

在評論裏說明的是index.[X].backend的默認值是elasticsearch,因此結果看似是徹底正確的。實際上,若此時配置index.search.backend=solr則索引不會建立在solr裏。由於只調用了index.sanguo.index-name=sanguosha這一配置,沒有對應的backend和hostname配置項。ui

規範的寫法應該是:this

#索引後端
index.sanguo.backend=elasticsearch
# ES服務的節點地址及端口,:9200能夠不寫
index.sanguo.hostname=mhostname1:9200,hostname2:9200,hostname3:9200
# 在ES中的索引別名
index.sanguo.index-name=sanguosha
複製代碼

如此,執行buildMixedIndex("sanguo")才萬無一失。這就是說配置文件裏能夠寫多套索引後端的配置,在使用時能夠酌情翻牌子。spa

經實測發現:翻譯

  • 配置裏三處[X]一致時能保證建立索引是按照配置項來的
  • buildMixedIndex建立索引時指定的參數值至少要在1個[X]處出現纔不會報Unknown external index backend的錯!

結語

有幫助的話,請點贊鼓勵一下~

JanusGraph實戰筆記系列:

JanusGraph學習筆記-問題與解決(一)

JanusGraph問題筆記(二)-SchemaViolationException

相關文章
相關標籤/搜索