图数据库 HugeGraph : IndexLabel
生活随笔
收集整理的這篇文章主要介紹了
图数据库 HugeGraph : IndexLabel
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
IndexLabel 用來(lái)定義索引類型,描述索引的約束信息,主要是為了方便查詢。
IndexLabel 允許定義的約束信息包括:name、baseType、baseValue、indexFeilds、indexType,下面逐一介紹。
- name: 屬性的名字,用來(lái)區(qū)分不同的 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: 要在哪些屬性上建立索引,可以是為多列建立聯(lián)合索引;
| by(String... fields) | files | allow to build index for multi fields for secondary index |
- indexType: 建立的索引類型,目前支持五種,即 Secondary、Range、Search、Shard 和 Unique。
- Secondary 支持精確匹配的二級(jí)索引,允許建立聯(lián)合索引,聯(lián)合索引支持索引前綴搜索
- 單個(gè)屬性,支持相等查詢,比如:person頂點(diǎn)的city屬性的二級(jí)索引,可以用g.V().has("city", "北京")查詢"city屬性值是北京"的全部頂點(diǎn)
- 聯(lián)合索引,支持前綴查詢和相等查詢,比如:person頂點(diǎn)的city和street屬性的聯(lián)合索引,可以用g.V().has ("city", "北京").has('street', '中關(guān)村街道')查詢"city屬性值是北京且street屬性值是中關(guān)村"的全部頂點(diǎn),或者g.V() .has("city", "北京")查詢"city屬性值是北京"的全部頂點(diǎn)
secondary index的查詢都是基于"是"或者"相等"的查詢條件,不支持"部分匹配"
- Range 支持?jǐn)?shù)值類型的范圍查詢
- 必須是單個(gè)數(shù)字或者日期屬性,比如:person頂點(diǎn)的age屬性的范圍索引,可以用g.V().has("age", P.gt(18))查詢"age屬性值大于18"的頂點(diǎn)。除了P.gt()以外,還支持P.gte(),?P.lte(),?P.lt(),?P.eq(),?P.between(),?P.inside()和P.outside()等
- Search 支持全文檢索的索引
- 必須是單個(gè)文本屬性,比如:person頂點(diǎn)的address屬性的全文索引,可以用g.V().has("address", Text .contains('大廈')查詢"address屬性中包含大廈"的全部頂點(diǎn)
search index的查詢是基于"是"或者"包含"的查詢條件
- 必須是單個(gè)文本屬性,比如:person頂點(diǎn)的address屬性的全文索引,可以用g.V().has("address", Text .contains('大廈')查詢"address屬性中包含大廈"的全部頂點(diǎn)
- Shard 支持前綴匹配 + 數(shù)字范圍查詢的索引
- N個(gè)屬性的分片索引,支持前綴相等情況下的范圍查詢,比如:person頂點(diǎn)的city和age屬性的分片索引,可以用g.V().has ("city", "北京").has("age", P.between(18, 30))查詢"city屬性是北京且年齡大于等于18小于30"的全部頂點(diǎn)
- shard index N個(gè)屬性全是文本屬性時(shí),等價(jià)于secondary index
- shard index只有單個(gè)數(shù)字或者日期屬性時(shí),等價(jià)于range index
shard index可以有任意數(shù)字或者日期屬性,但是查詢時(shí)最多只能提供一個(gè)范圍查找條件,且該范圍查找條件的屬性的前綴屬性都是相等查詢條件
- Unique 支持屬性值唯一性約束,即可以限定屬性的值不重復(fù),允許聯(lián)合索引,但不支持查詢
- 單個(gè)或者多個(gè)屬性的唯一性索引,不可用來(lái)查詢,只可對(duì)屬性的值進(jìn)行限定,當(dāng)出現(xiàn)重復(fù)值時(shí)將報(bào)錯(cuò)
- Secondary 支持精確匹配的二級(jí)索引,允許建立聯(lián)合索引,聯(lián)合索引支持索引前綴搜索
| 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 創(chuàng)建 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對(duì)象 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()總結(jié)
以上是生活随笔為你收集整理的图数据库 HugeGraph : IndexLabel的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Hbase 2.0 RegionObse
- 下一篇: CDH 6 安装 Hbase 二级索引