Wally Kolcz
Wally Kolcz

Reputation: 1664

Searching nodes and properties of nodes

I am trying to create a search function for my meetup app which uses Neo4j as the database. Is there a way to search both nodes (Topic, Department, and Title, getting the people that are attached to them) and properties of nodes (first name, last name, username, bio).

The Person node has a relationship to a Title node (via IS_TITLED) and a relationship to Department node (via EMPLOYED_BY) and relationship to Topic nodes (via INTEREST_OF or SKILL_OF)

Also I would like to make sure that the results are distinct for each person so if the person puts in the title of a person and a department and it gets 2 matches, then the person only returns once.

Upvotes: 0

Views: 67

Answers (2)

Wally Kolcz
Wally Kolcz

Reputation: 1664

Actually I wasn't looking for an entire application. My final solution was to add,update, and remove documents in ElasticSearch when my nodes where added, update, and removed. Then I use ElasticSearch to find results and return a list of node id's. Then I wrote my Cypher query to pull information using IN for the returned id's to produce the results. It seems to work perfectly. Since I couldn't find an integrated solution for syncing Neo4j and ElasticSearch, I use both libraries in my application and just perform the appropriate action on ElasticSearch when the nodes were effected.

Upvotes: 0

cybersam
cybersam

Reputation: 66967

Your question is very broad, but here is an example query that:

  • Finds all people employed by the Finance department and have the titled "Clerk".
  • Ensures they are distinct people.
  • Returns their first name, last name, username, and bio.

MATCH (d:Department)<-[:EMPLOYED_BY]-(p:Person)-[:IS_TITLED]->(t:Title)
WHERE d.name = "Finance" AND t.name = "Clerk"
WITH DISTINCT p
RETURN p.fname AS firstname, p.lname AS lastname, p.username AS username, p.bio AS bio;

Upvotes: 1

Related Questions