GQL Query Service Back to the query editor

Querying Wikidata, IMDB, dblp and more with GQL

This service answers queries in GQL, the ISO standard Graph Query Language (ISO/IEC 39075). The queries run on butterfly, a graph query engine that is specialised in path queries.

The service holds four property graphs, each in its own database: Wikidata, the IMDB movie database, dblp and the Mathematics Genealogy Project, and the German rail timetable. Choose the database with the selection next to the Examples button; a query runs on the selected database only. The choice is kept in the address (?db=gtfs), so links to a query include it, and choosing an example selects its database.

Wikidata

Items such as Q42 (Douglas Adams), connected by Wikidata properties such as P31 (instance of). Identified by their id: (:Q42).

IMDB

Nodes with the labels Person, Title, Movie, … connected by edges such as ActedIn. Identified by their properties: (:Person {name: 'Keanu Reeves'}).

dblp + Math Genealogy

Authors and their publications (Authored), and who supervised whose doctorate (AdvisedBy), linked where an author has an entry in both: (:Person {name: 'Wim Martens'}), (:Mathematician {name: 'Carl Friedrich Gauß'}).

German rail timetable

Every departure and arrival of a train on one day, connected by riding, staying on board and changing trains (Transfer, with the waiting time): (:Station {name: 'Bayreuth Hbf'}).

Your first query

A GQL query describes a pattern of nodes and edges in MATCH and says what to output in RETURN:

MATCH (cat)-[:P31]->(:Q146)
RETURN cat, cat.label AS catLabel
LIMIT 100

This query finds every node cat with an edge labelled P31 (instance of) to the node Q146 (house cat). It returns the node and its label. Write the query in the editor and press the run button or Ctrl+Enter.

The same works for IMDB, once IMDB is selected as the database:

MATCH (actor:Person)-[role:ActedIn]->(:Movie {title: 'The Matrix'})
RETURN actor.name AS actor, role.character AS character
Keywords such as MATCH, WHERE and RETURN must be written in upper case. Labels and property names are case sensitive too.

Datasets

Wikidata

The Wikidata subgraph is built from a Wikidata JSON dump.

WikidataProperty graphGQL
Item, property or lexeme A node. Its identity is the id, there is no separate id property. (:Q42), (x:Q42)
Statement (best rank only, like the wdt: prefix in SPARQL) An edge whose label is the property id (x)-[:P31]->(y)
Qualifier A property of the edge, keyed by the qualifier's property id -[e:P39]-> … e.P580
Label The node property label. It holds one label per item, in English if there is one. x.label
"no value" statement A node label wdno:P… instead of an edge

Descriptions, aliases and sitelinks are not part of the graph. References are not loaded. Because an item is identified by its id label, WHERE x = 'Q42' does not work: write (x:Q42) instead.

The target of an edge is another item or a value. Values are returned as follows:

Wikidata typeResultShown as
Item, property, lexemeWikidata entity URILink to Wikidata, with an explore button
Globe coordinateWKT point Point(lon lat)Map view
TimeDate and time (xsd:dateTime), without precisionDate, Timeline view
QuantityDecimal number, without its unitNumber, charts
Commons mediaURL of the file on Wikimedia CommonsImage grid view
Monolingual textText with a language tagText
URLURILink
String, external identifierTextText
Unknown value ("some value")Blank node

To find the id of an item or property, type its name after a colon in the editor and press Ctrl+Space, see Editor. You can also search on wikidata.org.

IMDB

The IMDB subgraph is built from the IMDB non-commercial datasets. Every node has the label Person, Title or AkaTitle. Titles have a second label for their type.

Node labelProperties
Person id (e.g. 'nm0000206'), name, birthYear, deathYear, profession (several values)
Title, together with one of Movie, Short, TVSeries, TVEpisode, TVMovie, TVMiniSeries, TVSpecial, TVShort, TVPilot, Video, VideoGame id (e.g. 'tt0133093'), titleType, title, originalTitle, isAdult, startYear, endYear, runtime (minutes), genre (several values), rating, votes
AkaTitle (title of a release in a region or language) title, region, language, ordering, type, attribute, isOriginalTitle
Edge labelFrom → toEdge properties
ActedIn, Produced, Composed, Edited, Filmed, Designed, Cast, ArchiveFootage, ArchiveSound, AppearedIn (as themselves), WorkedOn (any other job) Person → Title ordering (billing order), job, character
Directed, WrotePerson → Title
KnownForPerson → Title
EpisodeOfTVEpisode → seriesseasonNumber, episodeNumber
HasAkaTitle → AkaTitle

IMDB nodes are returned as their IMDB id, e.g. tt0133093. To show names and titles, return their properties: RETURN p.name AS name.

dblp and the Mathematics Genealogy Project

This database holds the computer science bibliography dblp (CC0) and the Mathematics Genealogy Project (MGP), which records who supervised whose doctorate, in one graph. About 11,000 people in dblp link to their MGP entry, so a path can lead from co-authors to academic ancestors.

Node labelProperties
Person (dblp) pid (dblp id, e.g. '95/3517'), name, alias (several values), affiliation, orcid
Publication (dblp), together with one of Article, InProceedings, Proceedings, Book, InCollection, PhdThesis, MastersThesis, Data key, title, year, venue, venueKey (e.g. 'conf/semweb' for ISWC and its workshops), doi
Mathematician (MGP) id, name, givenName, otherNames, familyName, mrAuthorId, descendants, and of the first doctorate degree, year, school, country, msc, subject, thesis
Degree, School, Country (MGP) type, year, title, msc, subject, school, country; name, country; name
Edge labelFrom → toEdge properties
Authored, EditedPerson → Publicationposition (1 = first author)
MathGenealogyPerson → Mathematician (the same person in the MGP)
AdvisedByMathematician → Mathematician (student to advisor)year, degree, school, country
Earned, AdvisorMathematician → Degree, Degree → Mathematician
GrantedBy, InDegree → School, School → Country

Names are spelled as on mathgenealogy.org and dblp.org, e.g. 'Domagoj Vrgoc'; people in dblp with the same name carry a number, e.g. 'Wei Wang 0001'. On a graph of this size, leave labels out of a Kleene star and filter the publications: a co-author chain through ISWC papers, ( ()-[:Authored]->(p WHERE p.venueKey = 'conf/semweb')<-[:Authored]-() )*, takes about a second, one through all of dblp about two minutes.

German rail timetable (GTFS)

The timetable of all trains in Germany (long-distance, regional and S-Bahn) on one day, Tuesday 27 October 2026, from the gtfs.de feed of DELFI e.V. (Creative Commons 4.0). It is a time-expanded graph: every departure and arrival of a train at a stop is a node, so every path through it is possible in time, and the waiting time of each change of trains is a property of its edge.

Node labelProperties
Stationid, name (e.g. 'Nürnberg Hbf'), lat, lon
Stop (a stop of a station)id, name, platform, lat, lon
Route (a line)id, line (e.g. 'RE38', 'ICE 25'), name, mode, agency
Dep, Arr (a departure or arrival of a train at a stop) time (815 for 08:15, above 2400 after midnight), clock ('08:15'), line, mode ('LongDistance', 'Regional' or 'Suburban'), station, platform; headsign on Dep
Edge labelFrom → toEdge properties
Board, AlightStop → Dep, Arr → Stop
RideDep → Arr at the next stopminutes
StayArr → Dep of the same train (staying on board)minutes
TransferArr → Dep of another train (a change)wait, walk (minutes)
PartOf, Footpath, ServesStop → Station, Stop → Stop, Route → Stopwalk on Footpath

A trip is the pattern Board Ride (Stay Ride)* (Transfer Ride (Stay Ride)*)* Alight, with one Kleene star for the legs of the trip and one inside it for the stops of a leg. A change leads to the first departure of each line and direction that can be reached, after at least 4 minutes. SHORTEST finds the trip with the fewest stops and changes, not the one that arrives first: ANY SHORTEST returns one of several equally short trips, which may differ from run to run, and ALL SHORTEST lists them all.

GQL syntax

butterfly implements the read-only part of GQL that is about pattern matching, with a focus on paths. This section describes what is supported. See Limitations for what is not.

Query structure

A query is a sequence of statements, ending with RETURN:

MATCH <pattern>, <pattern> [WHERE <condition>]
[OPTIONAL MATCH <pattern> …]
[MATCH …]
RETURN <expression> [AS <name>], …
[ORDER BY <expression> [ASC | DESC], …]
[SKIP <n>] [LIMIT <n>]

Patterns that share a variable are joined, whether they are separated by commas or in different MATCH statements. Comments are written as // … or /* … */.

Node patterns

PatternMatches
(x)any node, bound to the variable x
()any node, without a variable
(x:Movie), (x IS Movie)nodes with the label Movie
(x:Title:Movie)nodes with both labels
(x:Movie|Short)nodes with either label
(:Q42), (x:Q42)the Wikidata item Q42
(x {title: 'The Matrix', startYear: 1999})nodes with these property values
(x WHERE x.rating > 8)nodes that fulfil the condition

Edge patterns

PatternMatches
-[e:P31]->, <-[e:P31]-an edge with the label P31, pointing right or left
-[e]-, -an edge in either direction
->, <-any edge, without a variable
-[:P31|P279]->an edge with either label
-[e:P39 {P642: …}]->, -[e:P69 WHERE e.P580 IS NOT NULL]->edges with these properties (qualifiers)

Nodes and edges alternate. A chain can be as long as needed:

// Directors Keanu Reeves worked with
MATCH (:Person {name: 'Keanu Reeves'})-[:ActedIn]->(movie:Movie)<-[:Directed]-(director:Person)
RETURN director.name AS director, movie.title AS movie

Properties

x.name reads the property name of the node or edge x. For Wikidata, use the property id, e.g. e.P580 for the start time qualifier of the edge e.

Reading a property works like an inner join: rows where the node or edge does not have the property are dropped. A property with several values, like genre, produces one row per value.

WHERE

Conditions can be written after MATCH, inside a node or edge pattern, or inside a path pattern.

OperatorMeaning
=, <>The same node or value, e.g. m.title = 'The Matrix', a <> b
<, <=, >, >=Numeric comparison
+, -, *, /, %Arithmetic on numbers
AND, OR, XOR, NOTBoolean logic
IS NULL, IS NOT NULLTest for a missing value, e.g. after OPTIONAL MATCH
EXISTS { <pattern> }The pattern has a match. It may use variables of the outer query.
x IN (MATCH … RETURN y), x NOT IN (…)The node is (not) in the result of a subquery
// Nobel laureates in physics who also received the Nobel Prize in Chemistry
MATCH (p)-[:P166]->(:Q38104)
WHERE EXISTS { (p)-[:P166]->(:Q44585) }
RETURN p, p.label AS pLabel

OPTIONAL MATCH

OPTIONAL MATCH keeps the rows of the preceding patterns even if the optional pattern has no match. Its variables are then empty.

MATCH (country)-[:P31]->(:Q3624078)
OPTIONAL MATCH (country)-[:P36]->(capital)
RETURN country, country.label AS countryLabel, capital

Paths

Path queries are what butterfly is built for. A quantifier after an edge or after a parenthesised sub-pattern repeats it:

QuantifierRepetitions
*0 or more
+1 or more
?0 or 1
{n}, {m,n}, {,n}exactly n, m to n, at most n
// All subclasses of musical instrument (Q34379), like wdt:P279+ in SPARQL
MATCH (instrument)-[:P279]->+(:Q34379)
RETURN instrument, instrument.label AS instrumentLabel
// instance of a subclass of mountain, like wdt:P31/wdt:P279* in SPARQL
MATCH (mountain)-[:P31]->( ()-[:P279]-> )* (:Q8502)
RETURN mountain

A quantified sub-pattern can contain nodes with conditions and alternatives (|), and quantifiers can be nested. A variable inside a quantified sub-pattern is bound to the list of all its matches along the path:

// s is the list of stations on the route
MATCH ANY SHORTEST (:Q801394) ( () -[:P197]-> (s) )* (:Q742238)
RETURN [x IN s | x.label] AS stations

A prefix in front of the pattern selects which paths are returned:

PrefixReturns
noneone path for each pair of start and end node
ANY SHORTEST, ANYone shortest path for each pair
ALL SHORTESTall shortest paths for each pair
ALL, WALKall paths
TRAILall paths without a repeated edge
SIMPLE, ACYCLICall paths without a repeated node
Unlike standard GQL, a pattern without a prefix returns only one path per pair of nodes, not all paths. Prefer ANY SHORTEST over ALL SHORTEST and the other modes that return all paths, which can take much longer.

RETURN

RETURN lists the columns of the result. Give a column a name with AS; without it, n.label becomes a column named n__label. RETURN * returns all variables.

ORDER BY refers to the returned columns. It sorts nodes and properties by their internal id, which is not alphabetical. To sort numbers by value, sort by an arithmetic expression such as ORDER BY rating * 1 DESC.

A list comprehension turns a list variable into a list of values:

RETURN [m IN movie WHERE m.rating > 7 | m.title] AS goodMovies

Result views

Choose how the result is displayed with the menu above the result. A comment in the query selects the view that is used when the query is run:

// #defaultView:Map
MATCH (lighthouse)-[:P31]->(:Q39715), (lighthouse)-[:P17]->(:Q20), (lighthouse)-[:P625]->(coordinates)
RETURN lighthouse, lighthouse.label AS lighthouseLabel, coordinates
ViewNeeds
Tableanything
Mapa coordinates column (Wikidata P625)
ImageGridan image column (Wikidata P18 and other Commons media)
Timelinea date column (Wikidata time values)
GraphWikidata item columns; each row links its items from left to right
Tree, TreeMapWikidata item columns
BarChart, LineChart, AreaChart, ScatterChart, BubbleChart, Dimensionsa text column and number columns

For a Wikidata item in column x, a text column named xLabel is used as its label in the table, the graph and the map. Options can follow the view name, e.g. // #defaultView:ImageGrid{"hide": ["image"]} hides the column image.

Editor

Limitations

Examples

The query editor has example queries for all four databases. Open them with the Examples button; choosing an example also selects its database.