Creating edges in Arango WebUI - arangodb

I'm trying to add edges directly from the Arango WebUI-Graphs interface.
However, the interface complaints that:
Could not create edge: edge collection not used in graph
I'm actually using an edge collection in my graph, so it is unclear how to troubleshoot this error.

This is a bug with the web interface, and has been fixed in v3.5.0.
If you are not able to update to this version, you can create edges directly through the AQL interface:
<code>INSERT {
_from: "collection/vertex-id",
_to: "collection/vertex-id",
<your-other-properties>
} INTO <your-edge-collection>
</code>

Related

Is there a way to add properties containing lists via Gremlin in Cosmos DB?

I am looking to add a list property to an edge via gremlin in Cosmos DB. Currently, I it seems to only work with vertices,
g.addVertex('V1').property(list,'plist',1).property(list,'plist',2)
This works great, but
g.V().has('name','VertexName').as('a').V().has('name','VertexName2').addE('edge').from('a')
.property(list, 'metainfo', 'urls', {urls})
.property(list, 'metainfo', 'dates', "some date")
.property(list, 'metainfo', 'a', 1).property(list, 'metainfo', 'b', 2)
doesn't
The ApacheTinkerPop project currently defines Gremlin such that list and set cardinality properties are only allowed on vertices and not on edges.

Relationships are not displaying properly in Neo4J

I'm just starting out with Neo4j and I've been trying to send over simple relationships using Postman. I'm not having any issues sending the Nodes but the second I try to create a relationship, it creates two arbitrary grey nodes and builds the relationships. However, when I send a command like this:
CREATE (a:Person { name:'Tom Hanks', born:1956 })
-[r:ACTED_IN { roles: ['Forrest']}]->
(m:Movie { title:'Forrest Gump',released:1994 })
It properly displays the nodes and the relationship between them. See image below for more clarity.
This seems a bit odd as I would assume you'd be able to easily add nodes or create relationships at any point rather than when the Node's are being created.
Any feedback would be greatly appreciated.
Yes, you can create Relationship after the node is created using Match clause.
For e.g.
MATCH (node1:node),(node2:node)
WHERE node1.val=20 AND node2.val=21
CREATE (node1)-[r:Rel]->(node2)
RETURN r

Passing sets of properties and nodes as a POST statement wit KOA-NEO4J or BOLT

I am building a REST API which connects to a NEO4J instance. I am using the koa-neo4j library as the basis (https://github.com/assister-ai/koa-neo4j-starter-kit). I am a beginner at all these technologies but thanks to some help from this forum I have the basic functionality working. For example the below code allows me to create a new node with the label "metric" and set the name and dateAdded propertis.
URL:
/metric?metricName=Test&dateAdded=2/21/2017
index.js
app.defineAPI({
method: 'POST',
route: '/api/v1/imm/metric',
cypherQueryFile: './src/api/v1/imm/metric/createMetric.cyp'
});
createMetric.cyp"
CREATE (n:metric {
name: $metricName,
dateAdded: $dateAdded
})
return ID(n) as id
However, I am struggling to know how I can approach more complicated examples. How can I handle situations when I don't know how many properties will be added when creating a new node beforehand or when I want to create multiple nodes in a single post statement. Ideally I would like to be able to pass something like JSON as part of the POST which would contain all of the nodes, labels and properties that I want to create. Is something like this possible? I tried using the below Cypher query and passing a JSON string in the POST body but it didn't work.
UNWIND $props AS properties
CREATE (n:metric)
SET n = properties
RETURN n
Would I be better off switching tothe Neo4j Rest API instead of the BOLT protocol and the KOA-NEO4J framework. From my research I thought it was better to use BOLT but I want to have a Rest API as the middle layer between my front and back end so I am willing to change over if this will be easier in the longer term.
Thanks for the help!
Your Cypher syntax is bad in a couple of ways.
UNWIND only accepts a collection as its argument, not a string.
SET n = properties is only legal if properties is a map, not a string.
This query should work for creating a single node (assuming that $props is a map containing all the properties you want to store with the newly created node):
CREATE (n:metric $props)
RETURN n
If you want to create multiple nodes, then this query (essentially the same as yours) should work (but only if $prop_collection is a collection of maps):
UNWIND $prop_collection AS props
CREATE (n:metric)
SET n = props
RETURN n
I too have faced difficulties when trying to pass complex types as arguments to neo4j, this has to do with type conversions between js and cypher over bolt and there is not much one could do except for filing an issue in the official neo4j JavaScript driver repo. koa-neo4j uses the official driver under the hood.
One way to go about such scenarios in koa-neo4j is using JavaScript to manipulate the arguments before sending to Cypher:
https://github.com/assister-ai/koa-neo4j#preprocess-lifecycle
Also possible to further manipulate the results of a Cypher query using postProcess lifecycle hook:
https://github.com/assister-ai/koa-neo4j#postprocess-lifecycle

gremlin create edge while satisfying multiplicity constraint,if violated drop existing edge then create else just create it

I am struggling for quite some time to solve my problem which is like
I have a graph in which there are defined multiplicity constraints . When new edge is being created either a new edge can be created or it can violate the multiplicity constraint due to data being changed.
Now when data has changed I need to delete/drop the existing edge and create a new one. This is my problem. I am not able to drop and create the edge in single go.
What i have been trying is this
I am sending the query to gremlin server via node-gremlin module of nodejs.
relation i am trying to create is [merchant]-1--(sells)--*-> [product] . In given scenario only 1 merchant can sell a product . when some other merchant starts selling the product. I need to update it to reflect the new relation between them. It may be the case that no one was selling it previously so only new edge has to be created. finally the created edge is returned.
29 Jun 13:41:04 - [Error: An edge with the given label already exists on the in-vertex and the label [sells] is in-unique (Error 597)]
29 Jun
13:41:04 - { text:
'g.V().has(sIdKey,sIdVal).inE(edgeLabel).drop();graph.tx().commit();g.V().has(fIdKey,fIdVal).outE(edgeLabel).inV().has(sIdKey,sIdVal).tryNext().orElseGet{g.V().has(fIdKey,fIdVal).next().addEdge(edgeLabel,g.V().has(sIdKey,sIdVal).next());};',
params:
{ fIdKey: 'merchant_id',
fIdVal: 20230,
sIdKey: 'product_id',
sIdVal: 184504,
edgeLabel: 'sells' } }
The flow ii am trying to achieve is this
Find if existing edge is present -> delete the existing edge -> commit delete edge command --> create new edge --> commit new edge.
In the above query i have not written commit statement for add edge because i am committing add edges in bulk.
I am not able to figure out the how to proceed to solve this problem . any help would be great.
You need to iterate() on the drop operation before committing the transaction.
g.V().has(sIdKey,sIdVal).inE(edgeLabel).drop().iterate(); graph.tx().commit();
This is a common stumbling block and has been discussed previously: Gremlin drop() isn't working via java api

How to create and retrieve a graph database using java api in cassandra database

I am trying to create a graph having nodes and edges with some weights in Cassandra database using Titan Graph api . so how to retrieve this graph so that I could visualize it.
rexster or gremlin is the solution for it.. ?? If it so.. Please tell me the process.
I have a 4 cluster cassandra setup. I run titan on top of it. I made this program which creates two nodes and then create an edge between them and finally queries and prints it.
public static void main(String args[])
{
BaseConfiguration baseConfiguration = new BaseConfiguration();
baseConfiguration.setProperty("storage.backend", "cassandra");
baseConfiguration.setProperty("storage.hostname", "192.168.1.10");
TitanGraph titanGraph = TitanFactory.open(baseConfiguration);
Vertex rash = titanGraph.addVertex(null);
rash.setProperty("userId", 1);
rash.setProperty("username", "rash");
rash.setProperty("firstName", "Rahul");
rash.setProperty("lastName", "Chaudhary");
rash.setProperty("birthday", 101);
Vertex honey = titanGraph.addVertex(null);
honey.setProperty("userId", 2);
honey.setProperty("username", "honey");
honey.setProperty("firstName", "Honey");
honey.setProperty("lastName", "Anant");
honey.setProperty("birthday", 201);
Edge frnd = titanGraph.addEdge(null, rash, honey, "FRIEND");
frnd.setProperty("since", 2011);
titanGraph.commit();
Iterable<Vertex> results = rash.query().labels("FRIEND").has("since", 2011).vertices();
for(Vertex result : results)
{
System.out.println("Id: " + result.getProperty("userId"));
System.out.println("Username: " + result.getProperty("username"));
System.out.println("Name: " + result.getProperty("firstName") + " " + result.getProperty("lastName"));
}
}
My pom.xml, I just have this dependency:
<dependency>
<groupId>com.thinkaurelius.titan</groupId>
<artifactId>titan-cassandra</artifactId>
<version>0.5.4</version>
</dependency>
I am running Cassandra 2.1.2.
I don’t know much on gremlin, but I believe Gremlin is the shell that you can use to query your database from the command line. Rexter is an API that you can use on top of any other API that uses Blueprints (like Titan), to make your query/code accessible to others via REST API. Since you want to use embedded Java with titan, you don’t need gremlin. With the dependency that I have stated, blueprint API comes with it and using that API (like I have done in my code), you can do everything with your graph.
You might find this cheatsheet useful. http://www.fromdev.com/2013/09/Gremlin-Example-Query-Snippets-Graph-DB.html
First note that TitanGraph uses the Blueprints API, thus the Titan API is the Blueprints API. As you are using Blueprints you can use Gremlin, Rexster or any part of the TinkerPop stack to process your graph.
How you visualize your graph once in Titan is dependent on the graph visualization tools you choose. If I assume you are using Gephi or similar tool that can consume GraphML, then the easiest way to get the data from Titan would be to open a Gremlin REPL, get a reference to the graph and just do:
g = TitanFactory.open(...)
g.saveGraphML('/tmp/my-graph.xml')
From there you could import my-graph.xml into Gephi and visualize it.

Resources