cypher

Cypher Order by Path Cost

自作多情 提交于 2020-01-01 03:42:09
问题 I am extremely new to cypher and neo4j. I am wanting to get and order all paths between point A and B, based upon the total path cost. The cost in this case is a relationship property that is an integer. The path cost would be a summation of the relationship properties. I am looking at some examples of cypher's ORDER BY statement however, by the examples, it seems that you have to order by a property that is already assigned to the object being ordered, in this case that won't work because

Difference between merge and create unique in Neo4j

对着背影说爱祢 提交于 2019-12-31 11:43:07
问题 I'm trying to figure out what is the difference between MERGE and CREATE UNIQUE. I know these features: MERGE I'm able to create node, if doesn't exist pattern. MERGE (n { name:"X" }) RETURN n; This create node "n" with property name, empty node "m" and relationship RELATED. MERGE (n { name:"X" })-[:RELATED]->(m) RETURN n, m; CREATE UNIQUE I'm not able to create node like this. CREATE UNIQUE (n { name:"X" }) RETURN n; If exists node "n", create unique makes empty node "m" and relationship

How to use MERGE to create or reuse a part of pattern?

不问归期 提交于 2019-12-31 07:11:30
问题 I have node PRODUCT with multiple REVIEW node. I would create node PRODUCE if the product is not exist, then bind with REVIEW. For the example, I want a PRODUCE node {name:'X phone'} with 3 REVIEW {content:'best phone ever'}, {content:'worst phone ever'}, {content:'nope'}. I tried First, use one cypher MERGE for each REVIEW. MERGE(product:PRODUCT{name:'X phone'})-[:RATE]-(review:REVIEW{content:'best phone ever'}) MERGE(product:PRODUCT{name:'X phone'})-[:RATE]-(review:REVIEW{content:'worst

How can I efficiently create unique relationships in Neo4j?

只愿长相守 提交于 2019-12-31 06:59:07
问题 Following up on my question here, I would like to create a constraint on relationships. That is, I would like there to be multiple nodes that share the same "neighborhood" name, but each uniquely point to a particular city in which they reside. As encouraged in user2194039's answer, I am using the following index: CREATE INDEX ON :Neighborhood(name) Also, I have the following constraint: CREATE CONSTRAINT ON (c:City) ASSERT c.name IS UNIQUE; The following code fails to create unique

Optimize Create

最后都变了- 提交于 2019-12-31 05:10:40
问题 I got 20 000 apples. How do I create them in a smarter way than this? foreach (var a in apples) { graphClient.Cypher .Create("(a:Apple {newApple})") .WithParam("newApple", a) .ExecuteWithoutResults(); } Looking for a generic way to be able to pass objects without specifying each property. class Fruit { [JsonProperty(PropertyName = "Color")] public bool Color { get; set; } } class Apple : Fruit { [JsonProperty(PropertyName = "Variety")] public String Variety { get; set; } } 回答1: I suppose

Passing a Lucene query to Neo4j REST API using Cypher 2.0

无人久伴 提交于 2019-12-31 04:29:33
问题 If I have a Lucene query such as (title:"foo bar" AND body:baz*) OR title:bat is there any straightforward way to pass this into a Cypher query? It looks like this sort of used to work with START and the old node_auto_index but I'm not sure how to do this properly with Cypher 2.0. I've tried sticking it in the MATCH clause but I get invalid syntax errors: MATCH (item:Item {...}) RETURN item I'm about to write a parser that converts a Lucene query to a parameterized Cypher query but I thought

Getting the max record with different values using cypher

三世轮回 提交于 2019-12-31 04:19:45
问题 I have a graph with spatial data using the spatial plugin. This graph has "Threat Zones" (Polygons) which can be on top of the other so they also have a z-index property. Each "Threat Zone" is attached to 1 to N threat scenarios, sometimes multiple "Threat Zones" are attached to the same threat scenario, with different properties. I'm trying to get the top threat zone for each threat scenario, based on the z-index, for a specific location. This is my current query which is almost perfect:

Neo4j Cypher: copy relationships and delete node

风流意气都作罢 提交于 2019-12-31 04:09:10
问题 I'm trying to copy all inward relationships of a node (n) to another node (m) (both of witch I know the ids) before deleting (n) , but I couldn't come up with the code. The relationships may or may not exist. Anybody snippet? 回答1: You wont be able to create a relationshiptype dynamically from inside a collection of relationships. Suppose even if we collect all the incoming relationships as below START n=node(id1) MATCH n<-[r]-() WITH collect(r) as rels ... You would be able to iterate over

End UNWIND statement in a Cypher Query

纵然是瞬间 提交于 2019-12-31 02:46:22
问题 If I have a cypher query that unwinds a parameter, everything after that portion of the query is called x number of times of the unwind. I'd like to figure out a way to end the unwind and continue with other things. MATCH (thing:Thing) UNWIND { names } AS name CREATE thing-[:HAS_NAME]-(n:Name {name: name}) //done with the unwind WITH (thing) CREATE thing[:HAS_AGE]-(a:Age {age: 20}) In the above example, I will end up with two thing-[:HAS_AGE]->() relationships because of the unwind. Do I have

Search queries in neo4j: how to sort results in neo4j in START query with internal TFIDF / levenshtein or other algorithms?

北城余情 提交于 2019-12-30 05:32:05
问题 I am working on a model using wikipedia topics' names for my experiments in full-text index. I set up and index on 'topic' (legacy), and do a full text search for : 'united states' : start n=node:topic('name:(united states)') return n The first results are not relevant at all: 'List of United States National Historic Landmarks in United States commonwealths and territories, associated states, and foreign states' [...] and the actual 'united states' is buried deep down the list. As such, it