Skip to main content

FlureeQL Query Syntax

FlureeQL is a JSON-based query language for retrieving Fluree data. It is modeled as a JSON-representation of the W3C SPARQL standard.


Query Object

FlureeQL queries are JSON with the following keys:

keyrequired?type
@contextnoobject
fromyesstring or array
wherenoarray or object
selectyes*array or object
constructno*array
valuesnoarray
tnostring or integer
groupBynoarray or string
havingnoarray or string
orderBynostring or array
limitnointeger
offsetnointeger

NOTE: Either select or construct is required, but not both.

Advanced Features

FeatureDescription
Property PathsTraverse relationships across multiple hops
SubqueriesNest queries within queries
Time TravelQuery historical data using @t:, @iso:, or @sha: syntax
Value Map FiltersInline filters in where conditions
Federated QueriesQuery across multiple ledgers
Vector SearchSimilarity search with embeddings

Examples

Basic query example

{
"from": "cookbook/base",
"where": {
"@id": "?s",
"bestFriend": "?friend"
},
"select": {
"?s": [
"*",
{
"bestFriend": [
"*"
]
}
]
},
}

@context

required?type
noobject

Understanding the use of @context within the W3C JSON-LD standard can be important for using it properly within queries. For an explanation of how to use @context in FlureeQL, consider first reading our Guides page on Working with Context.

Examples

Example of a Query without @context

{
"from": "cookbook/base",
"where": {
"@id": "?s",
"@type": "http://example.org/Person"
},
"select": {
"?s": ["http://schema.org/name"]
}
}

Example of a Query with @context

{
"@context": { "schema": "http://schema.org/", "ex": "http://example.org/" },
"from": "cookbook/base",
"where": {
"@id": "?s",
"@type": "ex:Person"
},
"select": {
"?s": ["schema:name"]
}
}

from

required?type
yesstring

The from clause specifies the ledger to query. It takes the same value that would have been supplied to the /create endpoint when the ledger was created.

If I named a ledger "cookbook/base" when I created it, then when I queried it, I would use "from": "cookbook/base" to identify that this query should target that particular ledger.

Examples

Querying a ledger named "cookbook/base"

{
"@context": { "schema": "http://schema.org/", "ex": "http://example.org/" },
"from": "cookbook/base",
"where": {
"@id": "?s",
"@type": "ex:Person"
},
"select": {
"?s": ["schema:name"]
}
}

Next Steps