0

I have defined a Vertex with a schema and several of the properties of the vertex are of type boolean. I am trying now to query the vertex and filter the results by the boolean value of these properties.

I have tried:

g.V().hasLabel('Patient').has('alcohol_abuse', eq(true))
g.V().hasLabel('Patient').has('alcohol_abuse', true)
g.V().hasLabel('Patient').has('alcohol_abuse', constant(true))
g.V().hasLabel('Patient').has('alcohol_abuse', eq(1))

plus many more variations, none return the correct results

I expect to get the vertices in the Patient vertex with the property alcohol_abuse true.

Thanks

1 Answers1

2

That's strange - this:

g.V().hasLabel('Patient').has('alcohol_abuse', true)

or more succinctly, this:

g.V().has('Patient', 'alcohol_abuse', true)

should work. I did a quick test with TinkerGraph:

gremlin> g = TinkerGraph.open().traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> g.addV('Patient').property('alcohol_abuse',true).
......1>   addV('Patient').property('alcohol_abuse',false).iterate()
gremlin> g.V().has('Patient','alcohol_abuse',true).count()
==>1
gremlin> g.V().has('Patient','alcohol_abuse',false).count()
==>1

so that is definitely the expected outcome for all TinkerPop implementations including JanusGraph. If you don't see the solution to your problem, you might want to post the text of your Gremlin Console session to demonstrate.

stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • Thanks! After reviewing your post and looking through the data I had loaded, I determined that I had not loaded the true value correctly in the graph properties. I am loading this data via a CSV file and was not evaluating the text value of 'True' correctly. I have re-loaded the data and the query is working as you describe. Thanks Again – Shane Quint Apr 22 '19 at 23:17