Neo4J query to bring back user interests and other known users
I have an existing Neo4 query to bring back user interests and if any of those interests are related. The query is:
MATCH (u:User)-[r1:INTERESTED_IN]-(i1:Interest)
WHERE u.emailAddress = 'bob@mail.com'
OPTIONAL MATCH (u)-[r2:INTERESTED_IN]-(i2:Interest)
OPTIONAL MATCH (i1)-[r3:RELATED_TO]-(i2)
RETURN u, r1, i1, r2, i2, r3
This maps to a Spring Data Neo4J repository method as:
User findInterestsByEmailAddressIgnoreCase(@Param("emailAddress") String emailAddress);
I want to extend the graph so that users can know other users (e.g. bob knows fred and tom and fred and tom know each other too). How do I modify the same query to also bring back these relationships?
I tried adding an optional match for a user knowing another user as follows:
MATCH (u:User)-[r1:INTERESTED_IN]-(i1:Interest)
WHERE u.emailAddress = 'bob@mail.com'
OPTIONAL MATCH (u)-[r2:INTERESTED_IN]-(i2:Interest)
OPTIONAL MATCH (i1)-[r3:RELATED_TO]-(i2)
OPTIONAL MATCH (u:User)-[r5:KNOWS]-(u2:User)
RETURN u, r1, i1, r2, i2, r3, r5, u2
This seems to run and bring back the graph in the neo4j browser but Spring Data seems to fail with the error
org.springframework.dao.IncorrectResultSizeDataAccessException:
Incorrect result size: expected at most 1
at org.springframework.data.neo4j.repository.query.GraphQueryExecution$SingleEntityExecution.execute(GraphQueryExecution.java:83)
Any pointers on what I need to change in the query?
Updates
User class
@NodeEntity
public class User {
@Id
@GeneratedValue
private Long id;
public Long getId() {
return id;
}
@Index(unique = true)
private String emailAddress;
private String name;
@Relationship(type = "INTERESTED_IN", direction = Relationship.OUTGOING)
private Set<UserInterest> interests = new HashSet<>();
public Set<UserInterest> getInterests() {
return interests;
}
public void setInterests(Set<UserInterest> interests) {
this.interests = interests;
}
@Relationship(type = "KNOWS", direction = Relationship.UNDIRECTED)
private Set<RelatedUser> relatedUsers = new HashSet<>();
public Set<RelatedUser> getRelatedUsers() {
return relatedUsers;
}
public void setRelatedUsers(Set<RelatedUser> relatedUsers) {
this.relatedUsers = relatedUsers;
}
... additional getters/setters
}
neo4j cypher spring-data-neo4j
|
show 2 more comments
I have an existing Neo4 query to bring back user interests and if any of those interests are related. The query is:
MATCH (u:User)-[r1:INTERESTED_IN]-(i1:Interest)
WHERE u.emailAddress = 'bob@mail.com'
OPTIONAL MATCH (u)-[r2:INTERESTED_IN]-(i2:Interest)
OPTIONAL MATCH (i1)-[r3:RELATED_TO]-(i2)
RETURN u, r1, i1, r2, i2, r3
This maps to a Spring Data Neo4J repository method as:
User findInterestsByEmailAddressIgnoreCase(@Param("emailAddress") String emailAddress);
I want to extend the graph so that users can know other users (e.g. bob knows fred and tom and fred and tom know each other too). How do I modify the same query to also bring back these relationships?
I tried adding an optional match for a user knowing another user as follows:
MATCH (u:User)-[r1:INTERESTED_IN]-(i1:Interest)
WHERE u.emailAddress = 'bob@mail.com'
OPTIONAL MATCH (u)-[r2:INTERESTED_IN]-(i2:Interest)
OPTIONAL MATCH (i1)-[r3:RELATED_TO]-(i2)
OPTIONAL MATCH (u:User)-[r5:KNOWS]-(u2:User)
RETURN u, r1, i1, r2, i2, r3, r5, u2
This seems to run and bring back the graph in the neo4j browser but Spring Data seems to fail with the error
org.springframework.dao.IncorrectResultSizeDataAccessException:
Incorrect result size: expected at most 1
at org.springframework.data.neo4j.repository.query.GraphQueryExecution$SingleEntityExecution.execute(GraphQueryExecution.java:83)
Any pointers on what I need to change in the query?
Updates
User class
@NodeEntity
public class User {
@Id
@GeneratedValue
private Long id;
public Long getId() {
return id;
}
@Index(unique = true)
private String emailAddress;
private String name;
@Relationship(type = "INTERESTED_IN", direction = Relationship.OUTGOING)
private Set<UserInterest> interests = new HashSet<>();
public Set<UserInterest> getInterests() {
return interests;
}
public void setInterests(Set<UserInterest> interests) {
this.interests = interests;
}
@Relationship(type = "KNOWS", direction = Relationship.UNDIRECTED)
private Set<RelatedUser> relatedUsers = new HashSet<>();
public Set<RelatedUser> getRelatedUsers() {
return relatedUsers;
}
public void setRelatedUsers(Set<RelatedUser> relatedUsers) {
this.relatedUsers = relatedUsers;
}
... additional getters/setters
}
neo4j cypher spring-data-neo4j
You aren't COLLECT-ing any of the results, is i1 and i2 guaranteed to only return at most 1 value? Note that multiple values for any of the variables will result in a query with multiple rows. You will need to decide how you want to aggregate the results so that there is only 1 result.
– Tezra
Nov 12 '18 at 18:25
The first query is bringing back multiple rows but I don’t get the exception. I only get the exception when I extend the query to get the user connections.
– Swordfish
Nov 12 '18 at 18:29
Can you share the User class so that we can see what Spring is expecting?
– Tezra
Nov 12 '18 at 18:30
User class added above.
– Swordfish
Nov 12 '18 at 19:03
It looks like not all the class properties are listed at the top of the class, does this snippet include all of the class properties?
– Tezra
Nov 12 '18 at 19:22
|
show 2 more comments
I have an existing Neo4 query to bring back user interests and if any of those interests are related. The query is:
MATCH (u:User)-[r1:INTERESTED_IN]-(i1:Interest)
WHERE u.emailAddress = 'bob@mail.com'
OPTIONAL MATCH (u)-[r2:INTERESTED_IN]-(i2:Interest)
OPTIONAL MATCH (i1)-[r3:RELATED_TO]-(i2)
RETURN u, r1, i1, r2, i2, r3
This maps to a Spring Data Neo4J repository method as:
User findInterestsByEmailAddressIgnoreCase(@Param("emailAddress") String emailAddress);
I want to extend the graph so that users can know other users (e.g. bob knows fred and tom and fred and tom know each other too). How do I modify the same query to also bring back these relationships?
I tried adding an optional match for a user knowing another user as follows:
MATCH (u:User)-[r1:INTERESTED_IN]-(i1:Interest)
WHERE u.emailAddress = 'bob@mail.com'
OPTIONAL MATCH (u)-[r2:INTERESTED_IN]-(i2:Interest)
OPTIONAL MATCH (i1)-[r3:RELATED_TO]-(i2)
OPTIONAL MATCH (u:User)-[r5:KNOWS]-(u2:User)
RETURN u, r1, i1, r2, i2, r3, r5, u2
This seems to run and bring back the graph in the neo4j browser but Spring Data seems to fail with the error
org.springframework.dao.IncorrectResultSizeDataAccessException:
Incorrect result size: expected at most 1
at org.springframework.data.neo4j.repository.query.GraphQueryExecution$SingleEntityExecution.execute(GraphQueryExecution.java:83)
Any pointers on what I need to change in the query?
Updates
User class
@NodeEntity
public class User {
@Id
@GeneratedValue
private Long id;
public Long getId() {
return id;
}
@Index(unique = true)
private String emailAddress;
private String name;
@Relationship(type = "INTERESTED_IN", direction = Relationship.OUTGOING)
private Set<UserInterest> interests = new HashSet<>();
public Set<UserInterest> getInterests() {
return interests;
}
public void setInterests(Set<UserInterest> interests) {
this.interests = interests;
}
@Relationship(type = "KNOWS", direction = Relationship.UNDIRECTED)
private Set<RelatedUser> relatedUsers = new HashSet<>();
public Set<RelatedUser> getRelatedUsers() {
return relatedUsers;
}
public void setRelatedUsers(Set<RelatedUser> relatedUsers) {
this.relatedUsers = relatedUsers;
}
... additional getters/setters
}
neo4j cypher spring-data-neo4j
I have an existing Neo4 query to bring back user interests and if any of those interests are related. The query is:
MATCH (u:User)-[r1:INTERESTED_IN]-(i1:Interest)
WHERE u.emailAddress = 'bob@mail.com'
OPTIONAL MATCH (u)-[r2:INTERESTED_IN]-(i2:Interest)
OPTIONAL MATCH (i1)-[r3:RELATED_TO]-(i2)
RETURN u, r1, i1, r2, i2, r3
This maps to a Spring Data Neo4J repository method as:
User findInterestsByEmailAddressIgnoreCase(@Param("emailAddress") String emailAddress);
I want to extend the graph so that users can know other users (e.g. bob knows fred and tom and fred and tom know each other too). How do I modify the same query to also bring back these relationships?
I tried adding an optional match for a user knowing another user as follows:
MATCH (u:User)-[r1:INTERESTED_IN]-(i1:Interest)
WHERE u.emailAddress = 'bob@mail.com'
OPTIONAL MATCH (u)-[r2:INTERESTED_IN]-(i2:Interest)
OPTIONAL MATCH (i1)-[r3:RELATED_TO]-(i2)
OPTIONAL MATCH (u:User)-[r5:KNOWS]-(u2:User)
RETURN u, r1, i1, r2, i2, r3, r5, u2
This seems to run and bring back the graph in the neo4j browser but Spring Data seems to fail with the error
org.springframework.dao.IncorrectResultSizeDataAccessException:
Incorrect result size: expected at most 1
at org.springframework.data.neo4j.repository.query.GraphQueryExecution$SingleEntityExecution.execute(GraphQueryExecution.java:83)
Any pointers on what I need to change in the query?
Updates
User class
@NodeEntity
public class User {
@Id
@GeneratedValue
private Long id;
public Long getId() {
return id;
}
@Index(unique = true)
private String emailAddress;
private String name;
@Relationship(type = "INTERESTED_IN", direction = Relationship.OUTGOING)
private Set<UserInterest> interests = new HashSet<>();
public Set<UserInterest> getInterests() {
return interests;
}
public void setInterests(Set<UserInterest> interests) {
this.interests = interests;
}
@Relationship(type = "KNOWS", direction = Relationship.UNDIRECTED)
private Set<RelatedUser> relatedUsers = new HashSet<>();
public Set<RelatedUser> getRelatedUsers() {
return relatedUsers;
}
public void setRelatedUsers(Set<RelatedUser> relatedUsers) {
this.relatedUsers = relatedUsers;
}
... additional getters/setters
}
neo4j cypher spring-data-neo4j
neo4j cypher spring-data-neo4j
edited Nov 12 '18 at 19:03
asked Nov 12 '18 at 18:07
Swordfish
91213
91213
You aren't COLLECT-ing any of the results, is i1 and i2 guaranteed to only return at most 1 value? Note that multiple values for any of the variables will result in a query with multiple rows. You will need to decide how you want to aggregate the results so that there is only 1 result.
– Tezra
Nov 12 '18 at 18:25
The first query is bringing back multiple rows but I don’t get the exception. I only get the exception when I extend the query to get the user connections.
– Swordfish
Nov 12 '18 at 18:29
Can you share the User class so that we can see what Spring is expecting?
– Tezra
Nov 12 '18 at 18:30
User class added above.
– Swordfish
Nov 12 '18 at 19:03
It looks like not all the class properties are listed at the top of the class, does this snippet include all of the class properties?
– Tezra
Nov 12 '18 at 19:22
|
show 2 more comments
You aren't COLLECT-ing any of the results, is i1 and i2 guaranteed to only return at most 1 value? Note that multiple values for any of the variables will result in a query with multiple rows. You will need to decide how you want to aggregate the results so that there is only 1 result.
– Tezra
Nov 12 '18 at 18:25
The first query is bringing back multiple rows but I don’t get the exception. I only get the exception when I extend the query to get the user connections.
– Swordfish
Nov 12 '18 at 18:29
Can you share the User class so that we can see what Spring is expecting?
– Tezra
Nov 12 '18 at 18:30
User class added above.
– Swordfish
Nov 12 '18 at 19:03
It looks like not all the class properties are listed at the top of the class, does this snippet include all of the class properties?
– Tezra
Nov 12 '18 at 19:22
You aren't COLLECT-ing any of the results, is i1 and i2 guaranteed to only return at most 1 value? Note that multiple values for any of the variables will result in a query with multiple rows. You will need to decide how you want to aggregate the results so that there is only 1 result.
– Tezra
Nov 12 '18 at 18:25
You aren't COLLECT-ing any of the results, is i1 and i2 guaranteed to only return at most 1 value? Note that multiple values for any of the variables will result in a query with multiple rows. You will need to decide how you want to aggregate the results so that there is only 1 result.
– Tezra
Nov 12 '18 at 18:25
The first query is bringing back multiple rows but I don’t get the exception. I only get the exception when I extend the query to get the user connections.
– Swordfish
Nov 12 '18 at 18:29
The first query is bringing back multiple rows but I don’t get the exception. I only get the exception when I extend the query to get the user connections.
– Swordfish
Nov 12 '18 at 18:29
Can you share the User class so that we can see what Spring is expecting?
– Tezra
Nov 12 '18 at 18:30
Can you share the User class so that we can see what Spring is expecting?
– Tezra
Nov 12 '18 at 18:30
User class added above.
– Swordfish
Nov 12 '18 at 19:03
User class added above.
– Swordfish
Nov 12 '18 at 19:03
It looks like not all the class properties are listed at the top of the class, does this snippet include all of the class properties?
– Tezra
Nov 12 '18 at 19:22
It looks like not all the class properties are listed at the top of the class, does this snippet include all of the class properties?
– Tezra
Nov 12 '18 at 19:22
|
show 2 more comments
1 Answer
1
active
oldest
votes
According to the Spring-data-neo4j docs, the proper method signature is
// <class> finedBy<property><flags>(<property type> value)
User findByEmailAddressIgnoreCase(String emailAddress)
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%2f53267769%2fneo4j-query-to-bring-back-user-interests-and-other-known-users%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
According to the Spring-data-neo4j docs, the proper method signature is
// <class> finedBy<property><flags>(<property type> value)
User findByEmailAddressIgnoreCase(String emailAddress)
add a comment |
According to the Spring-data-neo4j docs, the proper method signature is
// <class> finedBy<property><flags>(<property type> value)
User findByEmailAddressIgnoreCase(String emailAddress)
add a comment |
According to the Spring-data-neo4j docs, the proper method signature is
// <class> finedBy<property><flags>(<property type> value)
User findByEmailAddressIgnoreCase(String emailAddress)
According to the Spring-data-neo4j docs, the proper method signature is
// <class> finedBy<property><flags>(<property type> value)
User findByEmailAddressIgnoreCase(String emailAddress)
answered Nov 12 '18 at 20:28
Tezra
5,00621042
5,00621042
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53267769%2fneo4j-query-to-bring-back-user-interests-and-other-known-users%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
You aren't COLLECT-ing any of the results, is i1 and i2 guaranteed to only return at most 1 value? Note that multiple values for any of the variables will result in a query with multiple rows. You will need to decide how you want to aggregate the results so that there is only 1 result.
– Tezra
Nov 12 '18 at 18:25
The first query is bringing back multiple rows but I don’t get the exception. I only get the exception when I extend the query to get the user connections.
– Swordfish
Nov 12 '18 at 18:29
Can you share the User class so that we can see what Spring is expecting?
– Tezra
Nov 12 '18 at 18:30
User class added above.
– Swordfish
Nov 12 '18 at 19:03
It looks like not all the class properties are listed at the top of the class, does this snippet include all of the class properties?
– Tezra
Nov 12 '18 at 19:22