Perform a SPARQL query on the database.
URL Parameters | |
---|---|
query | A URL-encoded SPARQL query operation. |
default-graph-uri* | The URI of the graph or graphs to use as the default graph. |
named-graph-uri* | The URI of a named graph or graphs to include in the query operation. |
database? | Perform this operation on the named content database instead of the default content database associated with the REST API instance. Using an alternative database requires the "eval-in" privilege; for details, see Security Requirements in the REST Application Developer's Guide. |
base? | The initial base IRI for the query. |
txid? |
The transaction identifier of the multi-statement transaction in
which to service this request. Use the /transactions
service to create and manage multi-statement transactions.
|
start? | The index of the first result to return. Results are numbered beginning with 1. Default: 1. This parameter only applies when evaluating a SPARQL SELECT query. |
pageLength? | The maximum number of results to return in this request. By default, all results are returned. This parameter is only applies when evaluating a SPARQL SELECT query. |
q? |
A string query. For details on the syntax, see
Searching Using String Queries in the Search Developer's Guide
and search:search .
|
structuredQuery? | A structured search query string. That is, a serialized representation of a search:query element. See Searching Using Structured Queries in the Search Developer's Guide. |
options? |
The name of query options previously created via a PUT or POST
request to the /v1/config/query service.
|
collection* | Filter results to include only matches in the named collection(s). |
directory? | Filter results to include only matches from documents in the specified database directory. |
optimize? | A number indicating how much time for the query engine to spend analyzing a query. (See sem:sparql.) |
bind:{name}* | A binding name and value. This format assumes that the type of the bind variable is an IRI. |
bind:{name}:{type}* | A binding name, type, and value. This parameter format accepts any XSD type, or a two-character language code. |
bind:{name}@{lang}* | A binding name, type, and value. Use this pattern to bind to language-tagged strings. |
ruleset* | The name of rulesets to include for inferring triples. Ruleset names can be those of the built-in rulesets, or user-managed rulesets stored in the schemas database. |
default-rulesets? |
A flag whether to include database-default inference or not.
Valid values are include (default) or exclude .
|
timestamp? |
A timestamp returned in the ML-Effective-Timestamp
header of a previous request. Use this parameter to fetch SPARQL query
results based on the database contents at a fixed point-in-time.
For more details, see
Performing Point-in-Time Operations in the REST Application Developer's Guide.
You cannot use this parameter with a SPARQL update.
|
Request Headers | |
---|---|
Accept* | The expected MIME type of the response. The response MIME type depends on the type of information generated by the query. For details, see Response Output Formats in the Semantics Developer's Guide. |
Response Headers | |
---|---|
Content-type | The MIME type of the data in the response body when performing a query. The MIME type depends on the type of information generated by the query. For details, see Response Output Formats in the Semantics Developer's Guide. |
ML-Effective-Timestamp |
The system timestamp at which this operation was performed. You
can use the value in the timestamp parameter of a
subsequent SPARQL query request. For more details, see
Performing Point-in-Time Operations in the REST Application Developer's Guide.
This header is only returned by SPARQL query requests.
|
Upon success, MarkLogic Server returns status 200 (OK) and the response body contains the query result. If your request results in an unsupported format, MarkLogic Server returns status 406 (Not Acceptable).
rest-reader
role, or the
following privilege:
http://marklogic.com/xdmp/privileges/rest-reader
This interface implements the GET method of the W3C SPARQL Protocol; for details, see http://www.w3.org/TR/2013/REC-sparql11-protocol-20130321#query-operation.
You can specify the RDF Dataset against which to execute the query
using the named-graph-uri
and
default-graph-uri
request parameters, or within the
query itself. If the dataset is specified in both the request
parameters and the query, the dataset defined by the request parameters
is used. If neither is specified, all graphs are included in the operation.
If the graph(s) you query use embedded (unmanaged) triples, you can
constrain your SPARQL query results to triples occurring in documents
that match document search criteria defined by the following parameters:
q
, structuredQuery
, and options
.
Applying document search criteria to graphs containing managed triples
is not recommended because it can yield unexpected results when the
search matches the internal documents in which triples are stored.
The collection lexicon must be enabled on the database when using using the GRAPH "?g" construct in SPARQL queries. You can check and enable this setting from the Admin Interface.
The response MIME type depends on the type of SPARQL query and the
Accept header MIME type. The four types of SPARQL query (
SELECT
, CONSTRUCT
, DESCRIBE
,
ASK
) return data in different formats.
For details, see Response Output Formats in the Semantics Developer's Guide.
=> This request uses the encoded version of this SPARQL query: SELECT ?s WHERE { ?s <http://dbpedia.org/ontology/director> <http://dbpedia.org/resource/Mexico> } $ curl --anyauth --user user:password -i -X GET \ -H "Accept: application/sparql-results+json" \ http://localhost:8000/v1/graphs/sparql?query="\ SELECT%20%3Fs%20%0AWHERE%20%7B%0A%20%20%3Fs%20%0A%20%20%3C\ http%3A%2F%2Fdbpedia.org%2Fontology%2Fdirector%3E%20%0A%20\ %20%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2FMexico%3E%20%0A%7D" ==> Run the SPARQL query passed as the URL encoded value of the query request parameter. MarkLogic Server responds with output similar to the following: HTTP/1.1 200 OK Content-type: application/sparql-results+json Server: MarkLogic Content-Length: 126 Connection: Keep-Alive Keep-Alive: timeout=5 { "head": { "vars": [ "s" ] }, "results": { "bindings": [ { "s": { "type": "uri", "value": "http://dbpedia.org/resource/Alfonso_Arau" } } ] } } If you set the Accept header to application/sparql-results+xml, MarkLogic Server returns data similar to the following: <sparql xmlns="http://www.w3.org/2005/sparql-results#"> <head> <variable name="s"/> </head> <results> <result> <binding name="s"> <uri>http://dbpedia.org/resource/Alfonso_Arau</uri> </binding> </result> </results> </sparql>
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.