Hello,
How to create indices on UDT the right way and be able to query them.
Schema:
schema.type('names') .ifNotExists() .property('id', UUID) .property('value', Text) .property('classification_ids', listOf(UUID)) .create() schema.type('hairColor') .ifNotExists() .property('id', UUID) .property('value', Text) .property('classification_ids', listOf(UUID)) .create() schema.type('height') .ifNotExists() .property('id', UUID) .property('value', Integer) .property('classification_ids', listOf(UUID)) .create() schema.vertexLabel('Person').ifNotExists() .partitionBy('id', UUID) .property('names', setOf(typeOf('names'))) .property('hairColor', setOf(typeOf('hairColor'))) .property('height', setOf(typeOf('height'))) .create() schema.vertexLabel('Person').searchIndex().ifNotExists().by('names').create() schema.vertexLabel('Person').searchIndex().ifNotExists().by('hairColor').create() schema.vertexLabel('Person').searchIndex().ifNotExists().by('height').create()
Data:
g.addV('Person').property('id', UUID.randomUUID()) .property('names', [ [ id: UUID.randomUUID(), value:'Name1', classification_ids: [UUID.randomUUID()] as List] as names] as Set) .property('hairColor', [ [ id: UUID.randomUUID(), value:'black', classification_ids: [UUID.randomUUID()] as List] as hairColor] as Set) .property('height', [ [ id: UUID.randomUUID(), value:160, classification_ids: [UUID.randomUUID()] as List] as height] as Set) g.addV('Person').property('id', UUID.randomUUID()) .property('names', [ [ id: UUID.randomUUID(), value:'Name2', classification_ids: [UUID.randomUUID()] as List] as names] as Set) .property('hairColor', [ [ id: UUID.randomUUID(), value:'brown', classification_ids: [UUID.randomUUID()] as List] as hairColor] as Set) .property('height', [ [ id: UUID.randomUUID(), value:150, classification_ids: [UUID.randomUUID()] as List] as height] as Set)
I want to query for a person with a specific name and classification_ids:
works:
g.V().hasLabel('Person').has('names.value', eq('Name1')).properties()
works not:
g.V().hasLabel('Person').has('names.value', eq('Name1')).has('names.classification_ids', contains('390e208d-eefc-4b03-ba17-6770336cf31e' as UUID)).properties()
error:
java.lang.IllegalArgumentException: Inconsistent types found for expression: [names contains 390e208d-eefc-4b03-ba17-6770336cf31e, names = Name1]
How to get this runnable?
UPDATE:
I also have to delete properties by a specific id (The id in UDT). This means id in UDT must be searchable, too.
If model changes are necessary, this is still possible.
thanks in advance
Josef