【实测】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

相关文章
相关标签/搜索