# Get relations of nodes found with a fulltext query

**URL:** <https://community.neo4j.com/t/get-relations-of-nodes-found-with-a-fulltext-query/60471>\
**Category:** Neo4j Graph Platform\
**Tags:** migrated\
**Created:** [June 27, 2022, 7:23am UTC](https://community.neo4j.com/t/get-relations-of-nodes-found-with-a-fulltext-query/60471 "2022-06-27T07:23:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![YourBro](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/yourbro/32/26276_2.png) [@YourBro](https://community.neo4j.com/u/YourBro)\
**Post date:** [June 27, 2022, 7:23am UTC](https://community.neo4j.com/t/get-relations-of-nodes-found-with-a-fulltext-query/60471/1 "2022-06-27T07:23:07Z")

</div>

Greetings dear community,

I would like to ask about how I can get relations of nodes found by means of a full text query, here is how my query looks like:

**CALL db.index.fulltext.queryNodes("SearchIndex", "\*p0420\*") YIELD node**

**WHERE node.isHidden IS NULL**

\*\*RETURN nod

\*\*So the found nodes could have a FaultCode label or Question label, both belong to the same index, what I want to do is, if the node label is FaultCode then I want to get its related questions, otherwise if the node label is Question, then I want to get its related fault code.

Can some help me express this in Cypher?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![YourBro](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/yourbro/32/26276_2.png) [@YourBro](https://community.neo4j.com/u/YourBro)\
**Post date:** [June 27, 2022, 9:33am UTC](https://community.neo4j.com/t/get-relations-of-nodes-found-with-a-fulltext-query/60471/2 "2022-06-27T09:33:09Z")

</div>

Thank you [@glilienfield](https://community.neo4j.com/t5/user/viewprofilepage/user-id/9010)

But, in my case in want to return related nodes not properties, based on the label of course. Is there a way to achieve that?

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [June 27, 2022, 8:32am UTC](https://community.neo4j.com/t/get-relations-of-nodes-found-with-a-fulltext-query/60471/3 "2022-06-27T08:32:06Z")

</div>

You could use a ‘case’ statement in the ‘return’ clause to conditionally return one or the other properties based on the labels.

**CALL db.index.fulltext.queryNodes("SearchIndex", "\*p0420\*") YIELD node**

**WHERE node.isHidden IS NULL**

**RETURN**

**case**

**when :FaultCode then node.faultCode**

**when :Question then node.question**

**end as result**

**[https://neo4j.com/docs/cypher-manual/current/syntax/expressions/#query-syntax-case](https://neo4j.com/docs/cypher-manual/current/syntax/expressions/#query-syntax-case)**

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [June 27, 2022, 12:04pm UTC](https://community.neo4j.com/t/get-relations-of-nodes-found-with-a-fulltext-query/60471/4 "2022-06-27T12:04:00Z")

</div>

Sorry for my misunderstanding. A simple approach would be to add an ‘option match’ for both relationship regardless of node type. You will get null results for the match that has no result. This would be ok if the optional match results are mutually exclusive, returning only on result for each node type.

another approach is to use one of the APOC library’s conditional procedures, which allow you to conditionally execute cypher queries. In your case the ‘case’ procedure seems appropriate. Your conditions would be the node labels, and the queries would be the match to get the relationships.

[https://neo4j.com/labs/apoc/4.1/overview/apoc/apoc.case/](https://neo4j.com/labs/apoc/4.1/overview/apoc/apoc.case/)

You can also use a ‘call’ subquery in a certain way to conditionally execute a block of cypher, but I don’t think this is applicable since you are returning data,
