{
  "id": "ciq-25",
  "title": "ContX IQ: Keep a Slow Condition on the Node-Type Indexes with condition.skip_resource_label",
  "description": "A read policy whose condition is matched on the node type labels only: condition.skip_resource_label leaves out the :Resource system label the platform otherwise adds to every named node, so the query planner works from :Person, :Bus and :LicenseNumber alone. Same Knowledge Query, same results, different plan. The example captures a three-node graph, saves the policy and the query, executes as the owner, and shows the Cypher the platform derives with and without the flag.",
  "category": "ContX IQ",
  "tags": [
    "ContX IQ",
    "CIQ Policy",
    "Knowledge Query",
    "Performance",
    "skip_resource_label",
    "Cypher"
  ],
  "api": "ContX IQ",
  "language": "Json",
  "lastUpdated": "2026-10-14",
  "openApiEndpoints": [
    "/capture/v1/nodes",
    "/capture/v1/relationships",
    "/configs/v1/authorization-policies",
    "/configs/v1/knowledge-queries",
    "/contx-iq/v1/execute"
  ],
  "relatedGuides": [
    "/guides/guide-contx-iq",
    "/guides/guide-ciq-cypher",
    "/guides/guide-data-schema"
  ],
  "commonErrors": [
    {
      "code": "422",
      "message": "skip_resource_label is not allowed for this policy version",
      "solution": "The flag is accepted on 1.0-ciq and 2.0-ciq policies. Remove it, or change the policy version."
    },
    {
      "code": "422",
      "message": "invalid node type `_DataSchemaNode` in cypher for node `<var>`",
      "solution": "A condition cannot match the data schema labels (_DataSchemaNode, _DataSchemaProperty, _DataSchemaRelationship, _DataSchemaMetadata). Read the schema through GET /data-schema/v1/ instead."
    },
    {
      "code": "401",
      "message": "insufficient API access level for appAgent",
      "solution": "The agent lacks ContXIQ (execute) or Capture (ingest). Add the permission to api_permissions."
    },
    {
      "code": "200",
      "message": "{\"data\": []}",
      "solution": "The token's sub is not the external_id of a Person who OWNS a Bus with a licence number, or the Token Introspect configuration does not match the token's issuer and audience. Check GET /contx-iq/v1/whoami for the subject the token resolves to."
    }
  ],
  "summary": "When a ContX IQ policy is saved, the platform rewrites its condition: every named node gets the :Resource system label, and the subject the :DigitalTwin label. The id and external_id indexes are defined on :Resource, a label every node carries, so for some conditions the planner starts from that index instead of a far cheaper plan based on the node type alone, such as a scan of a type with only a handful of nodes, and the query is slow.\n\ncondition.skip_resource_label (boolean, default false) leaves the :Resource label out. The planner then works from the node type labels alone; only the subject's :DigitalTwin label is still added. What the policy allows, and what the Knowledge Query returns, is unchanged: the flag changes the plan, not the result.\n\nRules:\n- Set it in condition, next to cypher and filter.\n- Accepted on 1.0-ciq and 2.0-ciq; a policy version that does not support it refuses the save with \"skip_resource_label is not allowed for this policy version\".\n- Measure first: the default plan is right for most conditions, and an unanchored or unbounded pattern stays slow with or without the flag (see \"Will my query time out?\" in the CIQ Cypher guide).",
  "usecase": "Scenario: a fleet application lets each person read the buses they own and the licence number of each bus. The pattern (:Person)-[:OWNS]->(:Bus)-[:HAS]->(:LicenseNumber) is anchored on the caller's external_id, yet its plan is slow because the planner starts from the :Resource index, which spans every node in the graph, instead of the few :Bus and :LicenseNumber nodes.\n\nGraph:\n- Person(karel), an identity node\n- Bus(harmonika), manufacturer Ikarus, model 280\n- LicenseNumber(ln-yyy)\n- karel -[OWNS]-> harmonika -[HAS]-> ln-yyy\n\nWalk:\n1. Capture the three nodes and two relationships.\n2. Save the policy with \"skip_resource_label\": true in condition, bound to the caller through $token.sub.\n3. Save the Knowledge Query reading bus.external_id, ln.external_id and the owns relationship.\n4. Execute as karel: one record, harmonika and ln-yyy, with the OWNS relationship and its id.\n5. Compare the Cypher the platform derives with and without the flag.",
  "requirements": "Prerequisites:\n- ServiceAccount credentials: For creating the policy and the Knowledge Query.\n- AppAgent credentials: For the Capture calls and the execute (X-IK-ClientKey). The agent must hold Capture and ContXIQ.\n- A user access token whose sub is \"karel\", validated by a Token Introspect configuration of the project (the policy binds the subject through $token.sub).\n\nRequired API access:\n- POST /capture/v1/nodes, POST /capture/v1/relationships\n- POST /configs/v1/authorization-policies\n- POST /configs/v1/knowledge-queries\n- POST /contx-iq/v1/execute",
  "steps": "Step 1: Capture the graph\n- Authentication: AppAgent credential.\n- Action: POST the three nodes, then the OWNS and HAS relationships.\n\nStep 2: Create the policy\n- Authentication: ServiceAccount credential.\n- Action: POST the 1.0-ciq policy. Its condition matches the owner's buses and their licence numbers, carries \"skip_resource_label\": true, and binds subject.external_id to $token.sub.\n- Result: the policy ID.\n\nStep 3: Create the Knowledge Query\n- Action: POST the query with policy_id set to the policy from step 2: nodes bus.external_id and ln.external_id, relationship owns.\n- Result: the query ID.\n\nStep 4: Execute as the owner\n- Authentication: AppAgent credential plus Authorization: Bearer with karel's token.\n- Action: POST /contx-iq/v1/execute with the query ID and no input parameters.\n- Result: 200 with one record: nodes bus.external_id \"harmonika\" and ln.external_id \"ln-yyy\", and the owns relationship whose Props.id is a GID.\n\nStep 5: Read the derived Cypher\n- The two forms the platform matches, with the flag and without. Only the labels differ; a query with the same policy minus the flag returns the same record.",
  "graph": {
    "caption": "The graph the example reads: karel OWNS the bus harmonika, which HAS the licence number ln-yyy. Hover a node for its properties, click it to highlight its neighbourhood.",
    "nodes": [
      {
        "external_id": "karel",
        "type": "Person",
        "is_identity": true,
        "properties": [
          {
            "type": "email",
            "value": "karel@demo.com"
          },
          {
            "type": "name",
            "value": "Karel Plihal"
          }
        ]
      },
      {
        "external_id": "harmonika",
        "type": "Bus",
        "properties": [
          {
            "type": "manufacturer",
            "value": "Ikarus"
          },
          {
            "type": "model",
            "value": "280"
          }
        ]
      },
      {
        "external_id": "ln-yyy",
        "type": "LicenseNumber",
        "properties": [
          {
            "type": "value",
            "value": "ln-yyy-value"
          }
        ]
      }
    ],
    "relationships": [
      {
        "source": "karel",
        "target": "harmonika",
        "type": "OWNS"
      },
      {
        "source": "harmonika",
        "target": "ln-yyy",
        "type": "HAS"
      }
    ]
  },
  "code": [
    {
      "step": "Step 1",
      "description": "Capture the owner, the bus and its licence number.",
      "filename": "POST https://eu.api.indykite.com/capture/v1/nodes",
      "language": "Json",
      "ingest": {
        "nodes": [
          {
            "external_id": "karel",
            "type": "Person",
            "is_identity": true,
            "properties": [
              {
                "type": "email",
                "value": "karel@demo.com"
              },
              {
                "type": "name",
                "value": "Karel Plihal"
              }
            ]
          },
          {
            "external_id": "harmonika",
            "type": "Bus",
            "properties": [
              {
                "type": "manufacturer",
                "value": "Ikarus"
              },
              {
                "type": "model",
                "value": "280"
              }
            ]
          },
          {
            "external_id": "ln-yyy",
            "type": "LicenseNumber",
            "properties": [
              {
                "type": "value",
                "value": "ln-yyy-value"
              }
            ]
          }
        ]
      }
    },
    {
      "description": "karel OWNS harmonika; harmonika HAS ln-yyy.",
      "filename": "POST https://eu.api.indykite.com/capture/v1/relationships",
      "language": "Json",
      "ingest": {
        "relationships": [
          {
            "source": {
              "external_id": "karel",
              "type": "Person"
            },
            "target": {
              "external_id": "harmonika",
              "type": "Bus"
            },
            "type": "OWNS"
          },
          {
            "source": {
              "external_id": "harmonika",
              "type": "Bus"
            },
            "target": {
              "external_id": "ln-yyy",
              "type": "LicenseNumber"
            },
            "type": "HAS"
          }
        ]
      }
    },
    {
      "step": "Step 2",
      "description": "The policy. skip_resource_label sits in condition next to cypher and filter; the filter binds the subject to the caller's token.",
      "filename": "policy.json",
      "language": "Json",
      "ingest": {
        "meta": {
          "policy_version": "1.0-ciq"
        },
        "subject": {
          "type": "Person"
        },
        "condition": {
          "cypher": "MATCH (subject:Person)-[owns:OWNS]->(bus:Bus)-[:HAS]->(ln:LicenseNumber)",
          "skip_resource_label": true,
          "filter": [
            {
              "attribute": "subject.external_id",
              "operator": "=",
              "value": "$token.sub"
            }
          ]
        },
        "allowed_reads": {
          "nodes": [
            "bus.*",
            "ln.*"
          ],
          "relationships": [
            "owns",
            "owns.*"
          ]
        }
      }
    },
    {
      "description": "Request to create the policy; the document is sent as a string in the policy field.",
      "filename": "POST https://eu.api.indykite.com/configs/v1/authorization-policies",
      "language": "Json",
      "ingest": {
        "project_id": "your_project_gid",
        "name": "ciq-policy-own-buses-skip-resource-label",
        "display_name": "CIQ policy - own buses and licence numbers (skip_resource_label)",
        "description": "Read the buses the caller owns and their licence numbers; the condition is matched on the node type labels only.",
        "policy": "{\"meta\":{\"policy_version\":\"1.0-ciq\"},\"subject\":{\"type\":\"Person\"},\"condition\":{\"cypher\":\"MATCH (subject:Person)-[owns:OWNS]->(bus:Bus)-[:HAS]->(ln:LicenseNumber)\",\"skip_resource_label\":true,\"filter\":[{\"attribute\":\"subject.external_id\",\"operator\":\"=\",\"value\":\"$token.sub\"}]},\"allowed_reads\":{\"nodes\":[\"bus.*\",\"ln.*\"],\"relationships\":[\"owns\",\"owns.*\"]}}",
        "status": "ACTIVE",
        "tags": []
      }
    },
    {
      "step": "Step 3",
      "description": "The Knowledge Query: two node references and the owns relationship, all within allowed_reads.",
      "filename": "knowledge_query.json",
      "language": "Json",
      "ingest": {
        "nodes": [
          "bus.external_id",
          "ln.external_id"
        ],
        "relationships": [
          "owns"
        ]
      }
    },
    {
      "description": "Request to create the Knowledge Query.",
      "filename": "POST https://eu.api.indykite.com/configs/v1/knowledge-queries",
      "language": "Json",
      "ingest": {
        "project_id": "your_project_gid",
        "name": "kq-own-buses-licence-numbers",
        "display_name": "Knowledge Query - own buses and their licence numbers",
        "description": "Returns the external IDs of the buses the caller owns and of their licence numbers, with the OWNS relationship.",
        "policy_id": "your_policy_gid",
        "query": "{\"nodes\":[\"bus.external_id\",\"ln.external_id\"],\"relationships\":[\"owns\"]}",
        "status": "ACTIVE"
      }
    },
    {
      "step": "Step 4",
      "description": "Execute as karel: X-IK-ClientKey plus Authorization: Bearer <karel's token>. No input parameters; the subject comes from the token.",
      "filename": "POST https://eu.api.indykite.com/contx-iq/v1/execute",
      "language": "Json",
      "ingest": {
        "id": "your_query_gid_or_name",
        "input_params": {},
        "page_token": 1
      }
    },
    {
      "description": "One record: the bus, its licence number and the OWNS relationship with its id.",
      "filename": "Response 200",
      "language": "Json",
      "ingest": {
        "data": [
          {
            "nodes": {
              "bus.external_id": "harmonika",
              "ln.external_id": "ln-yyy"
            },
            "relationships": {
              "owns": {
                "Id": 1155177702467043300,
                "ElementId": "5:3a2b09d5-...:1155177702467043332",
                "StartId": 4,
                "StartElementId": "4:3a2b09d5-...:4",
                "EndId": 8,
                "EndElementId": "4:3a2b09d5-...:8",
                "Type": "OWNS",
                "Props": {
                  "id": "gid:AAAAF...",
                  "create_time": "2026-10-14T09:12:04.731Z",
                  "update_time": "2026-10-14T09:12:04.731Z"
                }
              }
            }
          }
        ]
      }
    },
    {
      "step": "Step 5",
      "description": "The condition as the platform matches it, derived at save time. With the flag, the planner works from :Person, :Bus and :LicenseNumber alone; without it, every node also carries :Resource.",
      "filename": "derived-cypher.txt",
      "language": "Bash",
      "code": "-- what the platform matches, derived from the policy condition at save time\n\n-- default (skip_resource_label absent or false): every named node also carries Resource\nMATCH (subject:Person:DigitalTwin:Resource)-[owns:OWNS]->(bus:Bus:Resource)-[:HAS]->(ln:LicenseNumber:Resource)\n\n-- \"skip_resource_label\": true: only the subject's DigitalTwin label is added\nMATCH (subject:Person:DigitalTwin)-[owns:OWNS]->(bus:Bus)-[:HAS]->(ln:LicenseNumber)"
    }
  ],
  "links": {
    "html": "/resources/ciq-25",
    "markdown": "/resources/ciq-25.md",
    "openApi": "https://openapi.indykite.com/"
  }
}