简体   繁体   中英

Gremlin query for Cosmos Graph DB to get the graph structure surrounding a single vertex, filtering out nodes with specific labels

I am working with the Gremlin API to query a Cosmos Graph DB. I currently have a query that will return the graph structure surrounding a single vertex:

g.V('VERTEX_ID').repeat(__.outE().simplePath().subgraph('subGraph').inV()).until(__.outE().count().is(eq(0))).cap('subGraph')

I'm looking to add some filtering capability to exclude nodes with a certain property or label. Is this something that is possible? Attempting to avoid implementing the filtering with the resulting sub graph myself!

Thanks!

I guess you want to exclude the vertices in your subgraph but still follow their incident edges..? In that case, you'd make the subgraph step optional (depend on your filter criteria).

g.V('VERTEX_ID').
  repeat(__.outE().simplePath().sideEffect(
           __.not(__.bothV().hasLabel('foobar')).
              not(__.bothV().has('foo','bar')).
              subgraph('subGraph')).inV()).
    until(__.not(__.outE())).
  cap('subGraph')

The query above will follow all edges, but only include those in the subgraph that are not incident to a vertex with a foobar label or a foo property with the value bar .

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