序
在上一篇JanusGraph创建新图的文章中,一位热心同学提出一个很棒的问题,就是问我索引配置里官网N次提到的[X]到底是什么?自己动手实践了一番,整理成此文,以期探讨。
+++++++++++(贴原评):
略微一搜:JanusGraph的官网配置文档里[X]出现了上百次=>ES配置传送门
权威解释
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.
不权威翻译

实测
如【全程实战】怎么新建JanusGraph图并写入数据?所述的,关键的三个[X]是:
#索引后端
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配置项。
规范的写法应该是:
#索引后端
index.sanguo.backend=elasticsearch
# ES服务的节点地址及端口,:9200可以不写
index.sanguo.hostname=mhostname1:9200,hostname2:9200,hostname3:9200
# 在ES中的索引别名
index.sanguo.index-name=sanguosha
如此,执行buildMixedIndex("sanguo")才万无一失。这就是说配置文件里可以写多套索引后端的配置,在使用时可以酌情翻牌子。
经实测发现:
- 配置里三处[X]一致时能保证创建索引是按照配置项来的
- buildMixedIndex创建索引时指定的参数值至少要在1个[X]处出现才不会报Unknown external index backend的错!
结语
有帮助的话,请点赞鼓励一下~
JanusGraph实战笔记系列:
