Conversion of query from cypher to gremlin

0

I have cypher query: MATCH p=(c:Customer)-[:HAS_LOCATION|HAS_EMAIL|HAS_PHONE*1..25]-(n) return p

Now I want same query in gremlin .I have written this for gremlin is it right or can we write more optimized query

g.V().hasLabel('Customer').as('c') .repeat( both('HAS_LOCATION', 'HAS_EMAIL', 'HAS_PHONE') .simplePath() ) .times(1, 25) .path() .from('c') .toList()

質問済み 6ヶ月前199ビュー
1回答
1
承認された回答

A similar query in Gremlin would be:

g.V().hasLabel('Customer').
    repeat(bothE('HAS_LOCATION', 'HAS_EMAIL', 'HAS_PHONE') .otherV().simplePath()).
    emit().
    times(25).
    path().by(elementMap())

One thing to realize is that openCypher and Gremlin differ in how they build paths. By default, openCypher will only cross an edge once. With Gremlin and using simplePath(), a vertex/node is only traversed once.

This could also be an expensive query to execute if there are many nodes with a label of Customer. I would suggest that if using Neptune that you look to constrain the starting point for this query to one, or a subset, of starting nodes.

profile pictureAWS
回答済み 6ヶ月前
profile picture
エキスパート
レビュー済み 1ヶ月前
  • Thankyou for response

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ