find the particular node which fit three criteria neo4j
I would like to find the name node which trade with three fruits only.
I tried to use the following code in neo4j.
match (s:good)-[r:TRADES]-(n:Name)-[:TRADES]-(p:good)
WHERE (s.good = 'Apple' or s.good='Orange') and p.stock ='Grapes'
return s,n,p
where it returns the query as below.
However, I just want the following. Just the one who trade Grapes, Orange and Apple only.
I don't know which part of the cypher is incorrect. thank you for helping
neo4j
add a comment |
I would like to find the name node which trade with three fruits only.
I tried to use the following code in neo4j.
match (s:good)-[r:TRADES]-(n:Name)-[:TRADES]-(p:good)
WHERE (s.good = 'Apple' or s.good='Orange') and p.stock ='Grapes'
return s,n,p
where it returns the query as below.
However, I just want the following. Just the one who trade Grapes, Orange and Apple only.
I don't know which part of the cypher is incorrect. thank you for helping
neo4j
add a comment |
I would like to find the name node which trade with three fruits only.
I tried to use the following code in neo4j.
match (s:good)-[r:TRADES]-(n:Name)-[:TRADES]-(p:good)
WHERE (s.good = 'Apple' or s.good='Orange') and p.stock ='Grapes'
return s,n,p
where it returns the query as below.
However, I just want the following. Just the one who trade Grapes, Orange and Apple only.
I don't know which part of the cypher is incorrect. thank you for helping
neo4j
I would like to find the name node which trade with three fruits only.
I tried to use the following code in neo4j.
match (s:good)-[r:TRADES]-(n:Name)-[:TRADES]-(p:good)
WHERE (s.good = 'Apple' or s.good='Orange') and p.stock ='Grapes'
return s,n,p
where it returns the query as below.
However, I just want the following. Just the one who trade Grapes, Orange and Apple only.
I don't know which part of the cypher is incorrect. thank you for helping
neo4j
neo4j
asked Nov 22 '18 at 4:16
Platalea MinorPlatalea Minor
13411
13411
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
We have a knowledge base article on match intersection, what you're trying to do here, however your other restriction is that these are the only 3 connected nodes, so we have some additional work to do.
Using the first approach in the article, we just have to add an additional predicate to ensure the degree of :TRADES relationships equals the size of the collection:
WITH ['Apple', 'Orange', 'Grapes'] as names
MATCH (g:good)<-[:TRADES]-(n:Name)
WHERE g.good in names AND size((n)-[:TRADES]->()) = size(names)
WITH n, size(names) as inputCnt, count(DISTINCT g) as cnt
WHERE cnt = inputCnt
RETURN n
Hi @InverseFalcon I would like to know if I have another query with more than 5 fruits. What I need to need change is from three elements to five elements on WITH ['Apple', 'Orange', 'Grapes'] as names ?
– Platalea Minor
Dec 5 '18 at 8:17
The type of query provided doesn't use any hard-coded numbers for expected values, if you read through it you should notice it uses the number of elements in your input, so whether it's 3 or 5 or 5000 it should work the same.
– InverseFalcon
Dec 5 '18 at 9:28
However, if I want to query if any name node which have connected with three or more fruit nodes. I think this query won't be able to provide the name nodes?
– Platalea Minor
Dec 5 '18 at 9:40
Then just change up the last WHERE clause with the numbers you want:WHERE cnt >= 3
– InverseFalcon
Dec 5 '18 at 19:45
Hi @InverseFalcon Thank you for your help, yet it cannot resolve the question. I have raised another question below. If you have time please take a look. Thank you so much stackoverflow.com/questions/53629951/find-cluster-in-neo4j
– Platalea Minor
Dec 6 '18 at 5:11
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423820%2ffind-the-particular-node-which-fit-three-criteria-neo4j%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
We have a knowledge base article on match intersection, what you're trying to do here, however your other restriction is that these are the only 3 connected nodes, so we have some additional work to do.
Using the first approach in the article, we just have to add an additional predicate to ensure the degree of :TRADES relationships equals the size of the collection:
WITH ['Apple', 'Orange', 'Grapes'] as names
MATCH (g:good)<-[:TRADES]-(n:Name)
WHERE g.good in names AND size((n)-[:TRADES]->()) = size(names)
WITH n, size(names) as inputCnt, count(DISTINCT g) as cnt
WHERE cnt = inputCnt
RETURN n
Hi @InverseFalcon I would like to know if I have another query with more than 5 fruits. What I need to need change is from three elements to five elements on WITH ['Apple', 'Orange', 'Grapes'] as names ?
– Platalea Minor
Dec 5 '18 at 8:17
The type of query provided doesn't use any hard-coded numbers for expected values, if you read through it you should notice it uses the number of elements in your input, so whether it's 3 or 5 or 5000 it should work the same.
– InverseFalcon
Dec 5 '18 at 9:28
However, if I want to query if any name node which have connected with three or more fruit nodes. I think this query won't be able to provide the name nodes?
– Platalea Minor
Dec 5 '18 at 9:40
Then just change up the last WHERE clause with the numbers you want:WHERE cnt >= 3
– InverseFalcon
Dec 5 '18 at 19:45
Hi @InverseFalcon Thank you for your help, yet it cannot resolve the question. I have raised another question below. If you have time please take a look. Thank you so much stackoverflow.com/questions/53629951/find-cluster-in-neo4j
– Platalea Minor
Dec 6 '18 at 5:11
add a comment |
We have a knowledge base article on match intersection, what you're trying to do here, however your other restriction is that these are the only 3 connected nodes, so we have some additional work to do.
Using the first approach in the article, we just have to add an additional predicate to ensure the degree of :TRADES relationships equals the size of the collection:
WITH ['Apple', 'Orange', 'Grapes'] as names
MATCH (g:good)<-[:TRADES]-(n:Name)
WHERE g.good in names AND size((n)-[:TRADES]->()) = size(names)
WITH n, size(names) as inputCnt, count(DISTINCT g) as cnt
WHERE cnt = inputCnt
RETURN n
Hi @InverseFalcon I would like to know if I have another query with more than 5 fruits. What I need to need change is from three elements to five elements on WITH ['Apple', 'Orange', 'Grapes'] as names ?
– Platalea Minor
Dec 5 '18 at 8:17
The type of query provided doesn't use any hard-coded numbers for expected values, if you read through it you should notice it uses the number of elements in your input, so whether it's 3 or 5 or 5000 it should work the same.
– InverseFalcon
Dec 5 '18 at 9:28
However, if I want to query if any name node which have connected with three or more fruit nodes. I think this query won't be able to provide the name nodes?
– Platalea Minor
Dec 5 '18 at 9:40
Then just change up the last WHERE clause with the numbers you want:WHERE cnt >= 3
– InverseFalcon
Dec 5 '18 at 19:45
Hi @InverseFalcon Thank you for your help, yet it cannot resolve the question. I have raised another question below. If you have time please take a look. Thank you so much stackoverflow.com/questions/53629951/find-cluster-in-neo4j
– Platalea Minor
Dec 6 '18 at 5:11
add a comment |
We have a knowledge base article on match intersection, what you're trying to do here, however your other restriction is that these are the only 3 connected nodes, so we have some additional work to do.
Using the first approach in the article, we just have to add an additional predicate to ensure the degree of :TRADES relationships equals the size of the collection:
WITH ['Apple', 'Orange', 'Grapes'] as names
MATCH (g:good)<-[:TRADES]-(n:Name)
WHERE g.good in names AND size((n)-[:TRADES]->()) = size(names)
WITH n, size(names) as inputCnt, count(DISTINCT g) as cnt
WHERE cnt = inputCnt
RETURN n
We have a knowledge base article on match intersection, what you're trying to do here, however your other restriction is that these are the only 3 connected nodes, so we have some additional work to do.
Using the first approach in the article, we just have to add an additional predicate to ensure the degree of :TRADES relationships equals the size of the collection:
WITH ['Apple', 'Orange', 'Grapes'] as names
MATCH (g:good)<-[:TRADES]-(n:Name)
WHERE g.good in names AND size((n)-[:TRADES]->()) = size(names)
WITH n, size(names) as inputCnt, count(DISTINCT g) as cnt
WHERE cnt = inputCnt
RETURN n
answered Nov 22 '18 at 4:38
InverseFalconInverseFalcon
18.5k21829
18.5k21829
Hi @InverseFalcon I would like to know if I have another query with more than 5 fruits. What I need to need change is from three elements to five elements on WITH ['Apple', 'Orange', 'Grapes'] as names ?
– Platalea Minor
Dec 5 '18 at 8:17
The type of query provided doesn't use any hard-coded numbers for expected values, if you read through it you should notice it uses the number of elements in your input, so whether it's 3 or 5 or 5000 it should work the same.
– InverseFalcon
Dec 5 '18 at 9:28
However, if I want to query if any name node which have connected with three or more fruit nodes. I think this query won't be able to provide the name nodes?
– Platalea Minor
Dec 5 '18 at 9:40
Then just change up the last WHERE clause with the numbers you want:WHERE cnt >= 3
– InverseFalcon
Dec 5 '18 at 19:45
Hi @InverseFalcon Thank you for your help, yet it cannot resolve the question. I have raised another question below. If you have time please take a look. Thank you so much stackoverflow.com/questions/53629951/find-cluster-in-neo4j
– Platalea Minor
Dec 6 '18 at 5:11
add a comment |
Hi @InverseFalcon I would like to know if I have another query with more than 5 fruits. What I need to need change is from three elements to five elements on WITH ['Apple', 'Orange', 'Grapes'] as names ?
– Platalea Minor
Dec 5 '18 at 8:17
The type of query provided doesn't use any hard-coded numbers for expected values, if you read through it you should notice it uses the number of elements in your input, so whether it's 3 or 5 or 5000 it should work the same.
– InverseFalcon
Dec 5 '18 at 9:28
However, if I want to query if any name node which have connected with three or more fruit nodes. I think this query won't be able to provide the name nodes?
– Platalea Minor
Dec 5 '18 at 9:40
Then just change up the last WHERE clause with the numbers you want:WHERE cnt >= 3
– InverseFalcon
Dec 5 '18 at 19:45
Hi @InverseFalcon Thank you for your help, yet it cannot resolve the question. I have raised another question below. If you have time please take a look. Thank you so much stackoverflow.com/questions/53629951/find-cluster-in-neo4j
– Platalea Minor
Dec 6 '18 at 5:11
Hi @InverseFalcon I would like to know if I have another query with more than 5 fruits. What I need to need change is from three elements to five elements on WITH ['Apple', 'Orange', 'Grapes'] as names ?
– Platalea Minor
Dec 5 '18 at 8:17
Hi @InverseFalcon I would like to know if I have another query with more than 5 fruits. What I need to need change is from three elements to five elements on WITH ['Apple', 'Orange', 'Grapes'] as names ?
– Platalea Minor
Dec 5 '18 at 8:17
The type of query provided doesn't use any hard-coded numbers for expected values, if you read through it you should notice it uses the number of elements in your input, so whether it's 3 or 5 or 5000 it should work the same.
– InverseFalcon
Dec 5 '18 at 9:28
The type of query provided doesn't use any hard-coded numbers for expected values, if you read through it you should notice it uses the number of elements in your input, so whether it's 3 or 5 or 5000 it should work the same.
– InverseFalcon
Dec 5 '18 at 9:28
However, if I want to query if any name node which have connected with three or more fruit nodes. I think this query won't be able to provide the name nodes?
– Platalea Minor
Dec 5 '18 at 9:40
However, if I want to query if any name node which have connected with three or more fruit nodes. I think this query won't be able to provide the name nodes?
– Platalea Minor
Dec 5 '18 at 9:40
Then just change up the last WHERE clause with the numbers you want:
WHERE cnt >= 3
– InverseFalcon
Dec 5 '18 at 19:45
Then just change up the last WHERE clause with the numbers you want:
WHERE cnt >= 3
– InverseFalcon
Dec 5 '18 at 19:45
Hi @InverseFalcon Thank you for your help, yet it cannot resolve the question. I have raised another question below. If you have time please take a look. Thank you so much stackoverflow.com/questions/53629951/find-cluster-in-neo4j
– Platalea Minor
Dec 6 '18 at 5:11
Hi @InverseFalcon Thank you for your help, yet it cannot resolve the question. I have raised another question below. If you have time please take a look. Thank you so much stackoverflow.com/questions/53629951/find-cluster-in-neo4j
– Platalea Minor
Dec 6 '18 at 5:11
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423820%2ffind-the-particular-node-which-fit-three-criteria-neo4j%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown