2

Lot of years ago, I discussed with some neo4j engineers about the ability to query an unknown object given it's uuid.

At that time, the answer was that there was no general db index in neo4j.

Now, I have the same problem to solve:

each node I create has an unique id (uuid in the form <nx:u-<uuid>-?v=n> where ns is the namespace, uuid is a unique uuid and v=n is the version number of the element.

I'd like to have the ability to run the following cypher query:

match (n) where n.about = 'ki:u-SSD-v5.0?v=2' return n;

which actually return nothing.

The following query

match (n:'mm:ontology') where n.about = 'ki:u-SSD-v5.0?v=2' return n;

returns what I need, despite the fact that at query time I don't know the element type.

Can anyone help on this?

Paolo

Dave Bennett
  • 10,996
  • 3
  • 30
  • 41
Paolo Di Pietro
  • 517
  • 3
  • 17
  • is `uuid+version` unique or could multiple namespaces have the same `uuid+version`? – Dave Bennett Jun 25 '17 at 19:44
  • namespace + uid+version is unique. Of course, if namespace is not expanded, there is the possibility of duplication, but we can think of it as unique. Should be nice to have the ability to expand a namespace to build the correspondent IRI and use it as a index. – Paolo Di Pietro Jun 26 '17 at 13:19

1 Answers1

2

Have you considered adding a achema index to every node in the database for the about attribute?

For instance

Add a global label to all nodes in the graph (e.g. Node) that do not already have it. If your graph is overly large and/or heap overly small you will need to batch this operation. Something along the lines of the following...

MATCH (n)
WHERE NOT n:Node
WITH n
LIMIT 100000
SET n:Node

After the label is added then create an index on the about attribute for your new global label (e.g. Node). These steps can be performed interchangeably as well.

CREATE CONSTRAINT ON (node:Node) assert node.about IS UNIQUE

Then querying with something like the following

MATCH (n:Node) 
WHERE n.about = 'ki:u-SSD-v5.0?v=2' 
RETURN n;

will return the node you are seeking in a performant manner.

Dave Bennett
  • 10,996
  • 3
  • 30
  • 41
  • But doesn't run ;-( – Paolo Di Pietro Jun 26 '17 at 15:30
  • Did you add the `Node` label to all of your nodes? – Dave Bennett Jun 26 '17 at 15:34
  • Yes, all the nodes have an about label, as they comes from an rdf:Owl ontology, and about in Owl has the same role of uuid (not so easy, but accept the concept!). So, now I have the following elements loaded in my DB: `create constraint on (node:Node) assert node.about is unique;` `create (_ki_u_SSD_v5_0_v_2:`mm:ontology` { about: 'ki:u-SSD-v5.0?v=2', label: 'SSD-v5.0', collectionName: '/db/apps/ssd/ontology/public/SSD-v5.0', hasVersion: '2', decoded: 'true', hasCreationDate : '2013-04-11T18:09:45.735+02:00', label_it_IT : 'SSD-v5.0' });` – Paolo Di Pietro Jun 26 '17 at 15:47
  • But the query `match (sub:Node) where sub.about = 'ki:u-SSD-v5.0?v=2' return sub;` returns an empty set, while the query `MATCH (n:`mm:ontology`) RETURN n` return the expected record. – Paolo Di Pietro Jun 26 '17 at 15:52
  • 1
    if you type `:schema` in the browser what is returned? – Dave Bennett Jun 26 '17 at 15:52
  • Indexes ON :Node(about) ONLINE (for uniqueness constraint) ON :mm:ontology(about) ONLINE (for uniqueness constraint) ....... Constraints ON ( `mm:ontology`:`mm:ontology` ) ASSERT `mm:ontology`.about IS UNIQUE ON ( node:Node ) ASSERT node.about IS UNIQUE ..... – Paolo Di Pietro Jun 26 '17 at 15:56
  • 1
    yep - definitely won't work without the label. Without the label your query wouldn't match anything. I added a little extra to the answer to clear that up. – Dave Bennett Jun 26 '17 at 16:31
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/147640/discussion-between-paolo-di-pietro-and-dave-bennett). – Paolo Di Pietro Jun 26 '17 at 16:39