图数据库 HugeGraph : IndexLabel
生活随笔
收集整理的這篇文章主要介紹了
图数据库 HugeGraph : IndexLabel
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
IndexLabel 用來定義索引類型,描述索引的約束信息,主要是為了方便查詢。
IndexLabel 允許定義的約束信息包括:name、baseType、baseValue、indexFeilds、indexType,下面逐一介紹。
- name: 屬性的名字,用來區分不同的 IndexLabel,不允許有同名的屬性;
| indexLabel(String name) | name | y |
-
baseType: 表示要為 VertexLabel 還是 EdgeLabel 建立索引, 與下面的 baseValue 配合使用;
-
baseValue: 指定要建立索引的 VertexLabel 或 EdgeLabel 的名稱;
| onV(String baseValue) | baseValue | build index for VertexLabel: 'baseValue' |
| onE(String baseValue) | baseValue | build index for EdgeLabel: 'baseValue' |
- indexFeilds: 要在哪些屬性上建立索引,可以是為多列建立聯合索引;
| by(String... fields) | files | allow to build index for multi fields for secondary index |
- indexType: 建立的索引類型,目前支持五種,即 Secondary、Range、Search、Shard 和 Unique。
- Secondary 支持精確匹配的二級索引,允許建立聯合索引,聯合索引支持索引前綴搜索
- 單個屬性,支持相等查詢,比如:person頂點的city屬性的二級索引,可以用g.V().has("city", "北京")查詢"city屬性值是北京"的全部頂點
- 聯合索引,支持前綴查詢和相等查詢,比如:person頂點的city和street屬性的聯合索引,可以用g.V().has ("city", "北京").has('street', '中關村街道')查詢"city屬性值是北京且street屬性值是中關村"的全部頂點,或者g.V() .has("city", "北京")查詢"city屬性值是北京"的全部頂點
secondary index的查詢都是基于"是"或者"相等"的查詢條件,不支持"部分匹配"
- Range 支持數值類型的范圍查詢
- 必須是單個數字或者日期屬性,比如:person頂點的age屬性的范圍索引,可以用g.V().has("age", P.gt(18))查詢"age屬性值大于18"的頂點。除了P.gt()以外,還支持P.gte(),?P.lte(),?P.lt(),?P.eq(),?P.between(),?P.inside()和P.outside()等
- Search 支持全文檢索的索引
- 必須是單個文本屬性,比如:person頂點的address屬性的全文索引,可以用g.V().has("address", Text .contains('大廈')查詢"address屬性中包含大廈"的全部頂點
search index的查詢是基于"是"或者"包含"的查詢條件
- 必須是單個文本屬性,比如:person頂點的address屬性的全文索引,可以用g.V().has("address", Text .contains('大廈')查詢"address屬性中包含大廈"的全部頂點
- Shard 支持前綴匹配 + 數字范圍查詢的索引
- N個屬性的分片索引,支持前綴相等情況下的范圍查詢,比如:person頂點的city和age屬性的分片索引,可以用g.V().has ("city", "北京").has("age", P.between(18, 30))查詢"city屬性是北京且年齡大于等于18小于30"的全部頂點
- shard index N個屬性全是文本屬性時,等價于secondary index
- shard index只有單個數字或者日期屬性時,等價于range index
shard index可以有任意數字或者日期屬性,但是查詢時最多只能提供一個范圍查找條件,且該范圍查找條件的屬性的前綴屬性都是相等查詢條件
- Unique 支持屬性值唯一性約束,即可以限定屬性的值不重復,允許聯合索引,但不支持查詢
- 單個或者多個屬性的唯一性索引,不可用來查詢,只可對屬性的值進行限定,當出現重復值時將報錯
- Secondary 支持精確匹配的二級索引,允許建立聯合索引,聯合索引支持索引前綴搜索
| secondary() | Secondary | support prefix search |
| range() | Range | support range(numeric or date type) search |
| search() | Search | support full text search |
| shard() | Shard | support prefix + range(numeric or date type) search |
| unique() | Unique | support unique props value, not support search |
2.5.2 創建 IndexLabel
schema.indexLabel("personByAge").onV("person").by("age").range().ifNotExist().create(); schema.indexLabel("createdByDate").onE("created").by("date").secondary().ifNotExist().create(); schema.indexLabel("personByLived").onE("person").by("lived").search().ifNotExist().create(); schema.indexLabel("personByCityAndAge").onV("person").by("city", "age").shard().ifNotExist().create(); schema.indexLabel("personById").onV("person").by("id").unique().ifNotExist().create();2.5.3 刪除 IndexLabel
schema.indexLabel("personByAge").remove()2.5.4 查詢 IndexLabel
// 獲取IndexLabel對象 schema.getIndexLabel("personByAge")// 獲取property key屬性 schema.getIndexLabel("personByAge").baseType() schema.getIndexLabel("personByAge").baseValue() schema.getIndexLabel("personByAge").indexFields() schema.getIndexLabel("personByAge").indexType() schema.getIndexLabel("personByAge").name()總結
以上是生活随笔為你收集整理的图数据库 HugeGraph : IndexLabel的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Hbase 2.0 RegionObse
- 下一篇: CDH 6 安装 Hbase 二级索引