Accessing map values from neo4, apoc, Cypher












0















I am still rather new to Neo4j, Cypher and programming in general.



Is there a way to access the posted output below, i.e. access the "count" values for every "item“ (which has to be the pair), and also access the "item" values? I need the amount of how often a pair, i.e. specific neighboring nodes occur not only as information, but as values with which I can further work with in order to adjust my graph.



My last lines of code (in the preceding lines I just ordered the nodes sequentially):



...

WITH apoc.coll.pairs(a) as pairsOfa

WITH apoc.coll.frequencies(pairsOfa) AS giveBackFrequencyOfPairsOfa

UNWIND giveBackFrequencyOfPairsOfa AS x

WITH DISTINCT x

RETURN x


Output from the Neo4j Browser that I need to work with:



"x"            


│{"count":1,"item":[{"aName“:"Rob","time":1},{"aName":"Edwin“,"time“:2}]},{„count“:4,“item":[{"aName":"Edwin","time":2},{"aName“:"Celesta","time":3}]}

...









share|improve this question

























  • Your description is a little confusing. Can you provide an example of desired output with some additional context?

    – InverseFalcon
    Jan 2 at 23:01











  • Thank you, cybersam solved it below :)

    – CodeIsland
    Jan 3 at 9:08
















0















I am still rather new to Neo4j, Cypher and programming in general.



Is there a way to access the posted output below, i.e. access the "count" values for every "item“ (which has to be the pair), and also access the "item" values? I need the amount of how often a pair, i.e. specific neighboring nodes occur not only as information, but as values with which I can further work with in order to adjust my graph.



My last lines of code (in the preceding lines I just ordered the nodes sequentially):



...

WITH apoc.coll.pairs(a) as pairsOfa

WITH apoc.coll.frequencies(pairsOfa) AS giveBackFrequencyOfPairsOfa

UNWIND giveBackFrequencyOfPairsOfa AS x

WITH DISTINCT x

RETURN x


Output from the Neo4j Browser that I need to work with:



"x"            


│{"count":1,"item":[{"aName“:"Rob","time":1},{"aName":"Edwin“,"time“:2}]},{„count“:4,“item":[{"aName":"Edwin","time":2},{"aName“:"Celesta","time":3}]}

...









share|improve this question

























  • Your description is a little confusing. Can you provide an example of desired output with some additional context?

    – InverseFalcon
    Jan 2 at 23:01











  • Thank you, cybersam solved it below :)

    – CodeIsland
    Jan 3 at 9:08














0












0








0








I am still rather new to Neo4j, Cypher and programming in general.



Is there a way to access the posted output below, i.e. access the "count" values for every "item“ (which has to be the pair), and also access the "item" values? I need the amount of how often a pair, i.e. specific neighboring nodes occur not only as information, but as values with which I can further work with in order to adjust my graph.



My last lines of code (in the preceding lines I just ordered the nodes sequentially):



...

WITH apoc.coll.pairs(a) as pairsOfa

WITH apoc.coll.frequencies(pairsOfa) AS giveBackFrequencyOfPairsOfa

UNWIND giveBackFrequencyOfPairsOfa AS x

WITH DISTINCT x

RETURN x


Output from the Neo4j Browser that I need to work with:



"x"            


│{"count":1,"item":[{"aName“:"Rob","time":1},{"aName":"Edwin“,"time“:2}]},{„count“:4,“item":[{"aName":"Edwin","time":2},{"aName“:"Celesta","time":3}]}

...









share|improve this question
















I am still rather new to Neo4j, Cypher and programming in general.



Is there a way to access the posted output below, i.e. access the "count" values for every "item“ (which has to be the pair), and also access the "item" values? I need the amount of how often a pair, i.e. specific neighboring nodes occur not only as information, but as values with which I can further work with in order to adjust my graph.



My last lines of code (in the preceding lines I just ordered the nodes sequentially):



...

WITH apoc.coll.pairs(a) as pairsOfa

WITH apoc.coll.frequencies(pairsOfa) AS giveBackFrequencyOfPairsOfa

UNWIND giveBackFrequencyOfPairsOfa AS x

WITH DISTINCT x

RETURN x


Output from the Neo4j Browser that I need to work with:



"x"            


│{"count":1,"item":[{"aName“:"Rob","time":1},{"aName":"Edwin“,"time“:2}]},{„count“:4,“item":[{"aName":"Edwin","time":2},{"aName“:"Celesta","time":3}]}

...






neo4j cypher neo4j-apoc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 23:13









cybersam

40.8k53353




40.8k53353










asked Jan 2 at 22:38









CodeIslandCodeIsland

276




276













  • Your description is a little confusing. Can you provide an example of desired output with some additional context?

    – InverseFalcon
    Jan 2 at 23:01











  • Thank you, cybersam solved it below :)

    – CodeIsland
    Jan 3 at 9:08



















  • Your description is a little confusing. Can you provide an example of desired output with some additional context?

    – InverseFalcon
    Jan 2 at 23:01











  • Thank you, cybersam solved it below :)

    – CodeIsland
    Jan 3 at 9:08

















Your description is a little confusing. Can you provide an example of desired output with some additional context?

– InverseFalcon
Jan 2 at 23:01





Your description is a little confusing. Can you provide an example of desired output with some additional context?

– InverseFalcon
Jan 2 at 23:01













Thank you, cybersam solved it below :)

– CodeIsland
Jan 3 at 9:08





Thank you, cybersam solved it below :)

– CodeIsland
Jan 3 at 9:08












1 Answer
1






active

oldest

votes


















1














Based on your code, your result should contain multiple x records (not a single record, as implied by the "output" provided in your question). Here is an example of what I would expect:



╒══════════════════════════════════════════════════════════════════════╕
│"x" │
╞══════════════════════════════════════════════════════════════════════╡
│{"count":1,"item":[{"aName":"Rob","time":1},{"aName":"Edwin","time":2}│
│]} │
├──────────────────────────────────────────────────────────────────────┤
│{"count":1,"item":[{"aName":"Edwin","time":2},{"aName":"Celesta","time│
│":3}]} │
└──────────────────────────────────────────────────────────────────────┘


If that is true, then you can just access the count and item properties of each x directly via x.count and x.item. To get each value within an item, you could use x.item[0] and x.item[1].



Asides: you probably want to use apoc.coll.pairsMin instead of apoc.coll.pairs, to avoid the generation of a spurious "pair" (whose second element is null) when the number of values to be paired is odd. Also, you probably do not need the DISTINCT step.






share|improve this answer
























  • Thank you so very much! It is working. Such a simple solution that I just could not see yet. Now I can work from here :)

    – CodeIsland
    Jan 3 at 9:07











  • Any chance you could help improve the OP's question? It's difficult to see this Q/A as very helpful to many others.

    – rickhg12hs
    Jan 3 at 12:25











  • The question was really about the output - how to access "count" and "item" in the output; the output as was correctly given in cybersam's post.

    – CodeIsland
    Jan 3 at 14:21












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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54014093%2faccessing-map-values-from-neo4-apoc-cypher%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









1














Based on your code, your result should contain multiple x records (not a single record, as implied by the "output" provided in your question). Here is an example of what I would expect:



╒══════════════════════════════════════════════════════════════════════╕
│"x" │
╞══════════════════════════════════════════════════════════════════════╡
│{"count":1,"item":[{"aName":"Rob","time":1},{"aName":"Edwin","time":2}│
│]} │
├──────────────────────────────────────────────────────────────────────┤
│{"count":1,"item":[{"aName":"Edwin","time":2},{"aName":"Celesta","time│
│":3}]} │
└──────────────────────────────────────────────────────────────────────┘


If that is true, then you can just access the count and item properties of each x directly via x.count and x.item. To get each value within an item, you could use x.item[0] and x.item[1].



Asides: you probably want to use apoc.coll.pairsMin instead of apoc.coll.pairs, to avoid the generation of a spurious "pair" (whose second element is null) when the number of values to be paired is odd. Also, you probably do not need the DISTINCT step.






share|improve this answer
























  • Thank you so very much! It is working. Such a simple solution that I just could not see yet. Now I can work from here :)

    – CodeIsland
    Jan 3 at 9:07











  • Any chance you could help improve the OP's question? It's difficult to see this Q/A as very helpful to many others.

    – rickhg12hs
    Jan 3 at 12:25











  • The question was really about the output - how to access "count" and "item" in the output; the output as was correctly given in cybersam's post.

    – CodeIsland
    Jan 3 at 14:21
















1














Based on your code, your result should contain multiple x records (not a single record, as implied by the "output" provided in your question). Here is an example of what I would expect:



╒══════════════════════════════════════════════════════════════════════╕
│"x" │
╞══════════════════════════════════════════════════════════════════════╡
│{"count":1,"item":[{"aName":"Rob","time":1},{"aName":"Edwin","time":2}│
│]} │
├──────────────────────────────────────────────────────────────────────┤
│{"count":1,"item":[{"aName":"Edwin","time":2},{"aName":"Celesta","time│
│":3}]} │
└──────────────────────────────────────────────────────────────────────┘


If that is true, then you can just access the count and item properties of each x directly via x.count and x.item. To get each value within an item, you could use x.item[0] and x.item[1].



Asides: you probably want to use apoc.coll.pairsMin instead of apoc.coll.pairs, to avoid the generation of a spurious "pair" (whose second element is null) when the number of values to be paired is odd. Also, you probably do not need the DISTINCT step.






share|improve this answer
























  • Thank you so very much! It is working. Such a simple solution that I just could not see yet. Now I can work from here :)

    – CodeIsland
    Jan 3 at 9:07











  • Any chance you could help improve the OP's question? It's difficult to see this Q/A as very helpful to many others.

    – rickhg12hs
    Jan 3 at 12:25











  • The question was really about the output - how to access "count" and "item" in the output; the output as was correctly given in cybersam's post.

    – CodeIsland
    Jan 3 at 14:21














1












1








1







Based on your code, your result should contain multiple x records (not a single record, as implied by the "output" provided in your question). Here is an example of what I would expect:



╒══════════════════════════════════════════════════════════════════════╕
│"x" │
╞══════════════════════════════════════════════════════════════════════╡
│{"count":1,"item":[{"aName":"Rob","time":1},{"aName":"Edwin","time":2}│
│]} │
├──────────────────────────────────────────────────────────────────────┤
│{"count":1,"item":[{"aName":"Edwin","time":2},{"aName":"Celesta","time│
│":3}]} │
└──────────────────────────────────────────────────────────────────────┘


If that is true, then you can just access the count and item properties of each x directly via x.count and x.item. To get each value within an item, you could use x.item[0] and x.item[1].



Asides: you probably want to use apoc.coll.pairsMin instead of apoc.coll.pairs, to avoid the generation of a spurious "pair" (whose second element is null) when the number of values to be paired is odd. Also, you probably do not need the DISTINCT step.






share|improve this answer













Based on your code, your result should contain multiple x records (not a single record, as implied by the "output" provided in your question). Here is an example of what I would expect:



╒══════════════════════════════════════════════════════════════════════╕
│"x" │
╞══════════════════════════════════════════════════════════════════════╡
│{"count":1,"item":[{"aName":"Rob","time":1},{"aName":"Edwin","time":2}│
│]} │
├──────────────────────────────────────────────────────────────────────┤
│{"count":1,"item":[{"aName":"Edwin","time":2},{"aName":"Celesta","time│
│":3}]} │
└──────────────────────────────────────────────────────────────────────┘


If that is true, then you can just access the count and item properties of each x directly via x.count and x.item. To get each value within an item, you could use x.item[0] and x.item[1].



Asides: you probably want to use apoc.coll.pairsMin instead of apoc.coll.pairs, to avoid the generation of a spurious "pair" (whose second element is null) when the number of values to be paired is odd. Also, you probably do not need the DISTINCT step.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 2 at 23:26









cybersamcybersam

40.8k53353




40.8k53353













  • Thank you so very much! It is working. Such a simple solution that I just could not see yet. Now I can work from here :)

    – CodeIsland
    Jan 3 at 9:07











  • Any chance you could help improve the OP's question? It's difficult to see this Q/A as very helpful to many others.

    – rickhg12hs
    Jan 3 at 12:25











  • The question was really about the output - how to access "count" and "item" in the output; the output as was correctly given in cybersam's post.

    – CodeIsland
    Jan 3 at 14:21



















  • Thank you so very much! It is working. Such a simple solution that I just could not see yet. Now I can work from here :)

    – CodeIsland
    Jan 3 at 9:07











  • Any chance you could help improve the OP's question? It's difficult to see this Q/A as very helpful to many others.

    – rickhg12hs
    Jan 3 at 12:25











  • The question was really about the output - how to access "count" and "item" in the output; the output as was correctly given in cybersam's post.

    – CodeIsland
    Jan 3 at 14:21

















Thank you so very much! It is working. Such a simple solution that I just could not see yet. Now I can work from here :)

– CodeIsland
Jan 3 at 9:07





Thank you so very much! It is working. Such a simple solution that I just could not see yet. Now I can work from here :)

– CodeIsland
Jan 3 at 9:07













Any chance you could help improve the OP's question? It's difficult to see this Q/A as very helpful to many others.

– rickhg12hs
Jan 3 at 12:25





Any chance you could help improve the OP's question? It's difficult to see this Q/A as very helpful to many others.

– rickhg12hs
Jan 3 at 12:25













The question was really about the output - how to access "count" and "item" in the output; the output as was correctly given in cybersam's post.

– CodeIsland
Jan 3 at 14:21





The question was really about the output - how to access "count" and "item" in the output; the output as was correctly given in cybersam's post.

– CodeIsland
Jan 3 at 14:21




















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54014093%2faccessing-map-values-from-neo4-apoc-cypher%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]