Can I have two RETURN clauses in Cypher query? - cypher

I'm going through my first tutorial on Memgraph Playgound. In one od the lessons there is the following code:
MATCH (jon:Character { name: "Jon Snow" })-[killed:KILLED]->(character:Character)
RETURN jon, killed, character;
From the graph and the table, I can see that result returns 17 nodes.
I've modified the query to get the number of nodes instead of list of nodes:
MATCH (jon:Character { name: "Jon Snow" })-[killed:KILLED]->(character:Character)
RETURN count(jon);
Is it possible to have a query that would return both results at the same time, the count of nodes, as well as individual nodes? I've tried something like the following code but it doesn't work:
MATCH (jon:Character { name: "Jon Snow" })-[killed:KILLED]->(character:Character)
RETURN jon, killed, character;
RETURN count(jon);
Can you have more than one RETURN in a single query?

Related

Cypher query for gremlin traversal

New to cypher query
g.V().has('Entity1','id',within(id1)).in('Entity2').
where(__.out('Entity3').where(__.out('Entity4').has('name',within(name))))
how to convert the above gremlin to cypher and return adjacent Entity2 invertex.
Here condition is
out('Entity3') should be out of Entity2
out('Entity4') should be out of Entity3 and name in the provided list of values
Return adjacent vertex of inEntity2
Straight answer:
MATCH (m:Entity1 )<-[:Entity2]-(n)
WHERE (n)-[:Entity3]->()-[:Entity4]->({name: "ABC"})
AND m.id in ["id1"]
RETURN n
# Assuming id is a property here.
# If id is the actual ID of the node
MATCH (m:Entity1 )<-[:Entity2]-(n)
WHERE (n)-[:Entity3]->()-[:Entity4]->({name: "ABC"})
AND ID(m) in ["id1"]
RETURN n
I tried to create the graph for you use-case using this query:
CREATE (a:Entity2)-[:Entity2]->(b:Entity1 {id:"id1"}),
(a)-[:Entity3]->(:Entity3)-[:Entity4]->(:Entity4 {name:"ABC"})
the graph looks like this:
However, I think while writing your gremlin traversal you had the intention of specifying the label of the vertex rather than label of the edge. That is why in the query I wrote to create the graph, the relationship and the vertex, relationship is pointing to have same label.
If that is your intention then your cypher query would look like.
MATCH (:Entity1 {id:"id1"})<--(n:Entity2)
WHERE (n)-->(:Entity3)-->(:Entity4 {name: "ABC"})
RETURN n
I'm not 100% sure what you are looking for as the Gremlin above seems incomplete compared to the description but I think what you are looking for is something like this:
MATCH (e1:Entity1)<-[:Entity2]-(e2)-[:Entity3]->(e3)-[:Entity4]->(e4 {code: 'LHR'})
WHERE e1 IN (id1)
RETURN e2

Ambigious mongoDB query, matches everything

Why does this term match everything:
{result: $and[{$exists:true}, {$ne: 0}]}
{result:{$exists:true}, result:{$ne:0}} (this too as suggested)
The idea was to match fields, which have a key "result" and are where result is not equal zero. Why this does match a document, which only has a oid?
edit:
What works as expected is the following:
{ $and: [ { result:{$exists:true}}, {result:{$ne: 0}}]}
The question is still the same, why do those queries behaive like this?
try:
{result:{$exists:true}, result:{$ne:0}}

Azure Logic Apps: Set condition to False when SQL query returns no rows of data

How can i conditionally test the output from an Execute SQL Query to make sure it returns some rows of data.
In my example below if the query returns no rows I don't want it to send an email, I want to do something else. What is the test?
Thanks for your time
I test, if it queries result is no rows, the query body will be like this:
{
"OutputParameters": {},
"ResultSets": {}
}
So you could add a Condition with #{body('Execute_a_SQL_query')['OutputParameters']} is equal to {}. If true, do the things you want. Yo could set this in the Code view mode.
The below is the test result, hope this is what you want.
This will work in Query SQL V2.
What is does is takes the ResultSet and converts to string. This prevent s a null error on the length function. As an empty result set is {}, the length is 2. So if the length is 2 then the the result is empty.
"expression": {
"and": [
{
"equals": [
"#length(string(body('Execute_a_SQL_query_(V2)')?['ResultSets']))",
2
]
}
]
}
I am using similar to this in an until condition which runs until the length is zero. I guess you could do the same?
#equals(length(body('Execute_a_SQL_query')?['value']), 0)

RedisGraph - Combining multiple directives with MERGE

I am currently running the below query on Neo4J
match (p:Initial{state: 'Initial', name: 'Initial'}), (c:Encounter{code:'abcd', state: 'Encounter', name: 'Encounter1'})
merge (p)-[:raw {person_id:'1234', type:'Encounter', code:'abcd'}]->(c)
However I am unable to do the same query on RedisGraph.
According to what I have found so far, Redis does not seem to support combining MERGEwith other directives
Is there any workaround to this?
Can the query be changed to allow it to execute the same functionality without the match statement?
The only option I see right now is to split this into two queries,
The first one checks to see if p is connected to c:
MATCH (p:Initial{state: 'Initial', name: 'Initial'})-[:raw {person_id:'1234', type:'Encounter', code:'abcd'}]->(c:Encounter{code:'abcd', state: 'Encounter', name: 'Encounter1'}) RETURN p,c
If the above query returns empty issue a second query to form the relation:
MATCH (p:Initial{state: 'Initial', name: 'Initial'})(c:Encounter{code:'abcd', state: 'Encounter', name: 'Encounter1'}) CREATE (p)-[:raw {person_id:'1234', type:'Encounter', code:'abcd'}]->(c)

Boosting individual elasticsearch indices to have preference in results

I am trying to boost certain indices in my elastic search query. Right now, my query is looking like this.
var query = {
"query": {
"query_string": {
"fields": ["FirstName", "LastName"],
"query": "Hank Hill",
"default_operator": "AND"
}
}
};
var boosted_indices = {
"index_A" : 1.0,
"index_B" : 1.0,
"index_C" : 10.0
};
if (boosted_indices) {
query["indices_boost"] = boosted_indices;
}
// stringify and send query in an http.get request
I know that my query without boosting any indices works as I expect. However, I am still getting a lot of results from "index_A" in my query results, rather than the heavily boosted index_C. I know that there should be a similar number of matching results in A and C, so the issue must be that I am not boosting the query correctly.
Did I set up my query JSON incorrectly? On the tutorial I linked, it did not give much context.
One other thing I noticed.. the "_score" field for the returned documents... all of them are set to null. Might this have something to do with my documents not being boosted according to the index they came from?
I hope you are not using the sort parameter in query. This could be the reason that _score is null and you are not getting expected results.
Does this help?