API version: 0.3.0

---

# Writing a Cypher query

The [Cypher path query](/reference/search/cypher-path-subset.md) step lets you query the internal Neo4j database directly
with a **subset of Cypher 25**. This guide walks through building and running a query; see the
[reference page](/reference/search/cypher-path-subset.md) for the exact grammar and security constraints.

## Constraints to keep in mind

- The query must be **readonly** - no writes, no side effects.
- The query can only return a single variable named `paths`, of type
  [Path](https://neo4j.com/docs/cypher-manual/current/patterns/reference/#path-patterns).
- Function calls and existence clauses are not supported.

If you are not already familiar with Cypher, the [Neo4j Cypher manual](https://neo4j.com/docs/cypher-manual/current/) is
a good starting point, in particular its section on [patterns](https://neo4j.com/docs/cypher-manual/current/patterns/).

## Building your query

As small errors can break the whole query, it is recommended to build your query up slowly, e.g. first inside the
[Neo4j Browser](https://neo4j.com/docs/browser-manual/current/) or `cypher-shell` if you have direct access to the
database, before running it through [`POST /search`](/api/post-search.md). If a query is rejected, the response contains
the error code, message and position reported by Neo4j, see
[understanding search errors](/guide/search/understanding-search-errors.md).

As the base of your query you can use one of the provided [examples](/reference/search/cypher-path-subset.md#examples).

Generative AI like Claude and its competitors are usually experienced enough to help with Cypher query generation.

Parameters passed via the step's `parameters` object are available inside the query as `$parameterName` - see
[parameters and expressions](/guide/search/parameters-and-expressions.md) for details. Unlike the Elasticsearch query step,
`{{...}}`-expressions are not supported here.

## Example

### Request

```json
{
  "debug": true,
  "steps": [
    {
      "type": "cypher-path-subset",
      "query": "MATCH path=((:Plant)-[:HAS_TAG]->(:Tag {name: \"blue\"})) RETURN path"
    },
    {
      "type": "element-hydration"
    }
  ]
}
```

```bash
curl \
  -H 'Authorization: Bearer secret-token:PIPeJGUt7c00ENn8a5uDlc' \
  -H 'Content-Type: application/json' \
  --data-binary @payload.json \
  https://api.example.com/search
```

### Response

##### Response Body

```json
{
  "type": "_SearchResultResponse",
  "results": [
    {
      "type": "Plant",
      "id": "02IiNr0GOoKiPMM3n6dNmfvWddQqpN1iow5gs",
      "data": {
        "images": [
          {
            "description": "Strelitzia reginae or Bird of Paradise",
            "imageLinkFull": "https://upload.wikimedia.org/wikipedia/commons/5/55/Bird_of_Paradise_flower.JPG",
            "imageLinkThumbnail": "https://upload.wikimedia.org/wikipedia/commons/thumb/5/55/Bird_of_Paradise_flower.JPG/960px-Bird_of_...",
            "link": "https://en.wikipedia.org/wiki/File:Bird_of_Paradise_flower.JPG"
          },
          {
            "description": "Portugal, Madeira, Botanical garden in Funchal",
            "imageLinkFull": "https://upload.wikimedia.org/wikipedia/commons/6/68/2010-03-05_13_16_21_Portugal-Jardim_Bot%C3%A2nic...",
            "imageLinkThumbnail": "https://upload.wikimedia.org/wikipedia/commons/thumb/6/68/2010-03-05_13_16_21_Portugal-Jardim_Bot%C3...",
            "link": "https://en.wikipedia.org/wiki/File:2010-03-05_13_16_21_Portugal-Jardim_Bot%C3%A2nico_da_Madeira.jpg"
          }
        ],
        "createdAt": "2025-09-25T18:43:14+00:00",
        "updatedAt": "2025-09-25T18:43:14+00:00",
        "name": "Bird of Paradise",
        "scenario": "general.botanicExample",
        "scientificName": "S. reginae",
        "link": "https://en.wikipedia.org/wiki/Strelitzia_reginae",
        "description": "Strelitzia reginae, commonly known as the crane flower, bird of paradise, or isigude in Nguni,[3] is..."
      }
    },
    {
      "type": "Tag",
      "id": "02IiNr0GOoKiPMM4FOCWJ7N93GB5Ih1r74WAy",
      "data": {
        "description": "Blue is one of the three primary colours in the RGB (additive) colour model, as well as in the RYB c...",
        "createdAt": "2025-09-25T18:43:12+00:00",
        "updatedAt": "2025-09-25T18:43:12+00:00",
        "name": "blue",
        "color": "#4363d8",
        "scenario": "general.botanicExample",
        "link": "https://en.wikipedia.org/wiki/Blue"
      }
    },
    {
      "type": "HAS_TAG",
      "id": "02IiNr0GOoKiPMMG3SzbryY0vVeLSnkspLiXL",
      "start": "02IiNr0GOoKiPMM3n6dNmfvWddQqpN1iow5gs",
      "end": "02IiNr0GOoKiPMM4FOCWJ7N93GB5Ih1r74WAy",
      "data": {
        "createdAt": "2025-09-25T18:43:24+00:00",
        "updatedAt": "2025-09-25T18:43:24+00:00",
        "scenario": "general.botanicExample"
      }
    },
    "... 10 more items omitted (shapes seen: type:Plant, type:Tag, type:HAS_TAG) ..."
  ],
  "debug": [
    {
      "input": {
        "type": "cypher-path-subset",
        "query": "MATCH path=((:Plant)-[:HAS_TAG]->(:Tag {name: \"blue\"})) RETURN path",
        "parameters": {
          "stepResults": []
        }
      },
      "step-handler": "cypher-path-subset (App\\EventSystem\\SearchStep\\EventListener\\CypherPathSearchStepEventListener)",
      "start": 1758825857.489016,
      "end": 1758825857.750409,
      "duration": 0.26139283180236816
    },
    {
      "input": {
        "type": "element-hydration",
        "query": null,
        "parameters": {
          "stepResults": [
            {
              "paths": [
                {
                  "nodeIds": [
                    "02IiNr0GOoKiPMMTRjVFHTxeRcXTS8U2uHHvD",
                    "02IiNr0GOoKiPMM4FOCWJ7N93GB5Ih1r74WAy"
                  ],
                  "relationIds": [
                    "02IiNr0GOoKiPMN06V2Vd6foXx8M5oj4UBdv9"
                  ]
                },
                {
                  "nodeIds": [
                    "02IiNr0GOoKiPMM3n6dNmfvWddQqpN1iow5gs",
                    "02IiNr0GOoKiPMM4FOCWJ7N93GB5Ih1r74WAy"
                  ],
                  "relationIds": [
                    "02IiNr0GOoKiPMMG3SzbryY0vVeLSnkspLiXL"
                  ]
                },
                {
                  "nodeIds": [
                    "02IiNr0GOoKiPMMBJC6MvmdzszbF1DfOpDzCy",
                    "02IiNr0GOoKiPMM4FOCWJ7N93GB5Ih1r74WAy"
                  ],
                  "relationIds": [
                    "02IiNr0GOoKiPMN2qO7DkDedGvWv3XocVljHc"
                  ]
                },
                "... 3 more items omitted (shapes seen: nodeIds,relationIds) ..."
              ]
            }
          ]
        }
      },
      "step-handler": "element-hydration (App\\EventSystem\\SearchStep\\EventListener\\ElementHydrationSearchStepEventListener)",
      "start": 1758825857.75059,
      "element-hydration:redundantElementIds": {
        "message": "Removed 5 redundant elementIds.",
        "removedElementIds": [
          "02IiNr0GOoKiPMM4FOCWJ7N93GB5Ih1r74WAy"
        ]
      },
      "accessibleElementIds": [
        "02IiNr0GOoKiPMM3n6dNmfvWddQqpN1iow5gs",
        "02IiNr0GOoKiPMM4FOCWJ7N93GB5Ih1r74WAy",
        "02IiNr0GOoKiPMM95MrKH8ljX349BOQ3hyMlZ",
        "... 10 more items omitted (shapes seen: string) ..."
      ],
      "end": 1758825857.812404,
      "duration": 0.061814
    }
  ]
}
```

##### Response Headers

```http
Access-Control-Allow-Headers: *
Access-Control-Allow-Methods: OPTIONS, POST
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: ETag, Location
Allow: OPTIONS, POST
Cache-Control: no-cache, private
Content-Type: application/json; charset=utf-8
Date: Sat, 06 Sep 2025 14:57:35 GMT
Transfer-Encoding: chunked
X-Powered-By: Ember Nexus API
```

---

Home: [Ember Nexus API docs](/index.md)

Full site map: [llms.txt](/llms.txt)

Previous: [Writing an Elasticsearch query](/guide/search/writing-an-elasticsearch-query.md)

Next: [Parameters and expressions](/guide/search/parameters-and-expressions.md)
