简体   繁体   中英

How does searching for a vertex happen in graph databases using gremlin (Apache TinkerPop)?

I am working on modeling my data such as ->

data: [
 {
  id:"123",
  type:"a",
  attributes: [...]
 },
 {entity 2 ...},
 {entity 3 ...},
 ...
]

Is there a gremlin query I can use to fetch/get the vertex by type and id instead of just id? If not, would I have to traverse and search, if so what would the performance look like?

Type of entity in Gremlin is called Label .

To get a vertex by id and verify it has specific label you can run the query:

g.V('123').hasLabel('a').next()

If type is just a regular property (attribute) you can run:

g.V('123').has('type', 'a').next()

Performance depends on implementation, but getting vertex by id should be O(1) in any case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM