Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

search for value by key within dynamic collection

I am looking to extend discussion held here about filtering vertices based on property value from collection.
However, in my case the collection is dynamic e.g. generated using store

e.g.

following works using a static list ['red', 'green'].
I am able to filter out vertices with just 'red', 'green' as value in property 'color_name'.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

g.V().out().as('colors').store('color_list').by('name') 
.out()
.out().has('color_name', within(['red', 'green']))
.dedup()
.path()

but if I try to use collection from previous store it doesnt work.
color_list has same members as above. = ['red', 'green']

 g.V().out().as('colors').store('color_list').by('name')
    .out()
    .out().has('color_name', within('color_list'))
    .dedup()
    .path()

I must be missing something. My understanding of gremlin traversal is still in infancy.

>Solution :

For that to work you need to use a where step. The has step will interpret 'color_list' as a literal string and not the label for something named earlier in the query. The query needs to be along these lines:

 g.V().out().as('colors').store('color_list').by('name')
      .out()
      .out()
      .where(within('color_list'))
        .by('color_name')
        .by()
    .dedup()
    .path()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading