BR-ACC uses Neo4j’s Cypher query language to navigate the graph database. Cypher is a declarative pattern-matching language that makes it intuitive to query connected data.
The most common query is looking up a company by its unique identifier:
MATCH (c:Company)WHERE c.cnpj = $company_identifier OR c.cnpj = $company_identifier_formattedRETURN c, labels(c) AS entity_labels, elementId(c) AS entity_idLIMIT 1
From public_company_lookup.cypher - Production code used in the BR-ACC API
Search for either a Person (CPF) or Company (CNPJ):
MATCH (e)WHERE (e:Person AND (e.cpf = $identifier OR e.cpf = $identifier_formatted)) OR (e:Company AND (e.cnpj = $identifier OR e.cnpj = $identifier_formatted))RETURN e, labels(e) AS entity_labels, elementId(e) AS entity_idLIMIT 1
BR-ACC supports multiple entity types with different ID fields:
MATCH (e) WHERE (e.cpf = $id OR e.cnpj = $id OR e.contract_id = $id OR e.sanction_id = $id OR e.amendment_id = $id OR e.cnes_code = $id OR e.finance_id = $id OR e.embargo_id = $id OR e.school_id = $id OR e.convenio_id = $id OR e.partner_id = $id OR e.stats_id = $id OR elementId(e) = $id)AND (e:Person OR e:Partner OR e:Company OR e:Contract OR e:Sanction OR e:Election OR e:Amendment OR e:Finance OR e:Embargo OR e:Health OR e:Education OR e:Convenio OR e:LaborStats OR e:PublicOffice)RETURN e, labels(e) AS entity_labelsLIMIT 1
From entity_by_id.cypher - Supports all entity types in BR-ACC
BR-ACC includes a full-text search index across multiple entity types:
CALL db.index.fulltext.queryNodes("entity_search", $query)YIELD node, scoreWITH node, score, labels(node) AS node_labelsWHERE NONE(label IN node_labels WHERE label IN ['User', 'Investigation', 'Annotation', 'Tag']) AND (NOT $hide_person_entities OR NONE(label IN node_labels WHERE label IN ['Person', 'Partner'])) AND ($entity_type IS NULL OR ANY(label IN node_labels WHERE toLower(label) = $entity_type))RETURN node, score, node_labels, elementId(node) AS node_id, coalesce(node.cpf, node.cnpj, node.contract_id, node.sanction_id, node.amendment_id, node.cnes_code, node.finance_id, node.embargo_id, node.school_id, node.convenio_id, node.stats_id, elementId(node)) AS document_idORDER BY score DESCSKIP $skipLIMIT $limit
From search.cypher - Searches across name, razao_social, CPF, CNPJ, and other fields