0

I have two vertices with Label='Node'. Both vertices has name and value properties. One vertex value is numeric and other vertex value is string.

I want to search all vertices with value as "something". Since one of the vertices is numeric, it is not allowing me to compare against numeric property.

Is there a way to type cast numeric property value to string?

Here is the example:

Vertex#1: addV('Node').property('name','col1').property('value',123)

Vertex#2: addV('Node').property('name','col2').property('value',"ABC")

I want to find all vertices with Label "Node" where value can be any given string ("123" or "ABC")

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
Deepak KS
  • 3
  • 2
  • Is there a reason why you have a property key with different types of value on different vertices? In general this is not considered a good practice. There is no Gremlin step today that can check the type of a property like an (`instanceOf`) nor is there currently any built in way to cast a value. However, do you need to test these values in the query or just find them all? To find all the values you can do `g.V().has('Node')` but that could return a lot of results. You can however do something like this if you know the exact values you are looking for `g.V().has('Node',within('abc',1)` – Kelvin Lawrence Dec 07 '20 at 14:24
  • @KelvinLawrence how can I check the type of a VertextProperty? When I do `Object o1 = n1.property("name"); boolean isInt = o1.getClass() == Integer.class;` in Java I get a warning condition is always false. – canbax Aug 06 '21 at 09:05
  • Try using `instanceof` instead. – Kelvin Lawrence Aug 06 '21 at 12:50

0 Answers0