Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-09-2020 04:30 AM
Hello I am trying to put constraint on relationship's attribute. My relationship and nodes files are separate. the relationship file has timestamp filed which is unique . previously I put constraints on nodes and my query gets more faster performance than before. Now I need to put constraint on relationships attribute. From doc I have seen that it is possible to put constraint in relationship attribute. I did that but not getting better speed for query performance
CREATE CONSTRAINT ON (r:owns) ASSERT r.TIMESTAMP IS UNIQUE
my timestamp field is string format but I am casting it in date time. do I need to put constraint at casted datetime value. My data size is 7million +
01-09-2020 04:35 AM
While you can add a constraint on relationship properties, it does not create an index on the relationship, which is why you're not seeing a corresponding increase in query speed. A way to get around this, is to place a node in the middle of your relationship that has the properties that you're trying to index on, like:
(n1)-[:RELATIONSHIP]->(:Node with properties you care about)-[:RELATIONSHIP]->(:n2)
This will allow you to index the property you're currently trying to set on the relationship and should increase your query speed.
01-09-2020 04:44 AM
unfortunately I don't have nodes with TIMESTAMP property. Only relationship contains timestamp property
01-09-2020 05:13 AM
I'm aware that you don't currently have that node. I'm just telling you that if you have that property on your relationship then you're not going to be able to enjoy the increased query speed you are after. You might decided to change your data model in which case you could probably do a simple query like:
MATCH (n1)-[r:relationship {timeStamp: data})->(n2)
MERGE (n1)-[:RELATIONSHIP]->(:Timestamp {timeStamp: r.timeStamp})-[:RELATIONSHIP]->(n2)
DELETE r
Something of that nature and get the desired result. But that's just suggestion.
01-09-2020 01:25 PM
Just pointing out, that constraint you have there:
CREATE CONSTRAINT ON (r:owns) ASSERT r.TIMESTAMP IS UNIQUE
Is a node constraint on :owns nodes, not on relationships.
At present the only relationship constraints we support are existence constraints on relationship properties
01-13-2020 12:41 AM
I am getting this after performing this query
CREATE CONSTRAINT ON ()-[owns: OWN]-() ASSERT exists(owns.TIMESTAMP)
Unable to create CONSTRAINT ON ()-[ owns:OWN]-() ASSERT exists(owns.TIMESTAMP):
Relationship(744882451) with type OWN
must have the property `TIMESTAMP
01-13-2020 01:25 PM
Yes, the error is telling you that there is a relationship in your graph (with id() = 744882451) that is an :OWN relationship and doesn't have a TIMESTAMP property. Since this would violate the constraint, the constraint cannot be created.
You may want to make sure all of your :OWN relationships adhere to the constraint you want to add before creating the constraint.
11-01-2021 03:43 AM
Hi Andrew. I want to have constraints on relationships, but I found this in documentation "Node key constraints, node property existence constraints and relationship property existence constraints are only available in Neo4j Enterprise Edition. Databases containing one of these constraint types cannot be opened using Neo4j Community Edition." Does this mean that there is no way for community edition users to have constraints on relationship ?
11-01-2021 06:09 PM
Currently that is true. Here's a checklist of feature sets between the two editions:
With Neo4j 4.x, given that enterprise edition has more differentiators than before to set it apart from community (causal clustering, multi-database, and advanced security features and configuration being some of the big ones) I think that there is opportunity to revisit some of the more common features that were previously the big differentiators but now might be relaxed.
Some features, such as listing and killing queries/transactions, I think is going through the process of being released to community edition. There hasn't been commitment yet for constraints, but it is in the realm of consideration, and I'll likely be among those pushing for releasing those. At this point though there's no guarantee yet.
You might consider Neo4j Aura as a means to run Enterprise edition at a more affordable point, if that's your main blocker.
11-01-2021 07:47 PM
Thank you Andrew! Waiting for new updates about this topic!
01-12-2020 10:41 PM
@MuddyBootsCode @andrew.bowman I have tried full text schema index on relationship like
call db.index.fulltext.createRelationshipIndex("timestampindex",["owns"," has"],["TIMESTAMP"],{eventually_consistent:"true"})
and tried to query
call db.index.fulltext.queryRelationships("timestampindex","match ()-[r:owns]->(d)
with datetime(r.TIMESTAMP) as dateval,d,type(r) as transactiontype
where dateval.year=2019 and dateval.month=03 and dateval.day=01 and dateval.hour>=10 and dateval.hour<12
return dateval.hour,d.ID,transactiontype,dateval ")
and got bellow error
Neo.ClientError.Procedure.ProcedureCallFailed
Failed to invoke procedure db.index.fulltext.queryRelationships
: Caused by: org.apache.lucene.queryparser.classic.ParseException: Encountered " ")" ") "" at line 1, column 7.
Was expecting one of:
** ...**
** "+" ...**
** "-" ...**
** ...**
** "(" ...**
** "*" ...**
** ...**
** ...**
** ...**
** ...**
** ...**
** "[" ...**
** "{" ...**
** ...**
** ...**
I never used this full text schema before but my instinct is saying I have missed something here. Could you help me out please
Thanks
All the sessions of the conference are now available online