Retrieve endpoint
- Last Updated: December 3, 2026
- 5 minute read
- Documentation
The /v1/retrieve endpoint is the primary search interface for MarkLogic Retrieval API (MRA). It provides powerful document search capabilities using text queries, vectors, constraint-based filters, and collection labels.
Overview
The retrieve endpoint searches for documents in the MarkLogic Server database and returns a list of matching document URIs. It supports:
- Text Search: Full-text search using MarkLogic Server's search capabilities (supports phrase search with double quotes)
- Vector Search (MarkLogic Server 12 and up): Vector similarity search using embeddings
- Constraint Filters: Apply filters based on document properties
- Collection Labels: Filter by MarkLogic Server collections with MustHave/MustNotHave logic
- Entity Inputs: Accepted for future entity expansion; non-empty values currently return a warning
- Relation Inputs: Accepted for future relation expansion; non-empty values currently return a warning
- Result Limiting: Control the number of results returned
Basic usage
HTTP POST is recommended for most queries, especially those with complex parameters.
curl -X POST http://localhost:8003/v1/retrieve \
-H "Content-Type: application/json" \
--digest -u admin:admin \
-d '{
"text": "heart disease treatment",
"topk": 20,
"labels": {
"medical-data": {
"constraintValue": "MustHave"
}
}
}'
GET requests are supported and useful for testing with a web browser, but require URL-encoded parameters.
curl -X GET "http://localhost:8003/v1/retrieve?text=diabetes&topk=5" \
--digest -u admin:admin
Parameters
text (string)
The search query text. Performs full-text search across document content. See Searching Using String Queries.
Important: Empty text parameter returns empty results (not all documents)
Syntax:
- Individual words (AND):
"diabetes treatment"- matches documents containing BOTH 'diabetes' AND 'treatment' - OR operator:
"diabetes OR treatment"- matches documents containing 'diabetes' OR 'treatment' (or both) - Exact phrase:
"\"chronic bronchitis\""- matches only the exact phrase "chronic bronchitis" - Mixed query (AND):
"\"heart disease\" treatment"- matches documents with exact phrase "heart disease" AND word "treatment" - Phrase with OR:
"\"heart disease\" OR diabetes"- matches documents with exact phrase "heart disease" OR word 'diabetes' - Multiple phrases (AND):
"\"Type 2 diabetes\" \"insulin resistance\""- matches documents with BOTH exact phrases - Multiple OR operators:
"asthma OR diabetes OR hypertension"- matches documents with any of these terms
Behavior:
- Default boolean logic is AND (all terms must match)
- Use explicit
ORoperator for union behavior (any term matches) - Phrases must use double quotes (
") for exact matching - Empty quoted phrases (
"") return no results - Results are ordered by relevance score
topk (integer)
Maximum number of results to return for each search type (full-text or vector). When both full-text and vector searches run, the merged result set may contain up to 2ร this value. Default is 10.
labels (object)
Collection-based filtering with MustHave/MustNotHave constraints. Keys are collection names, values specify whether documents must have or must not have that collection.
Structure:
{
"text": "clinical trials",
"labels": {
"collection1": {
"constraintValue": "MustHave"
},
"collection2": {
"constraintValue": "MustNotHave"
}
}
}
filters (object)
Constraint-based filtering using MarkLogic Server constraints. Filters allow you to narrow results by document properties, ranges, or custom constraints.
Structure:
{
"text": "clinical trials",
"filters": {
"categoryValueConstraint": {
"constraintType": "Value",
"constraintValue": "cardiovascular"
},
"statusConstraint": {
"constraintType": "Value",
"constraintValue": "completed"
}
}
}
๐ For comprehensive filter documentation, see Filters.
vectors (object)
Vector search using embeddings. Keys are embedding names, values are arrays of numbers representing the embedding vectors.
Structure:
{
"vectors": {
"embedding1": [0.1, 0.2, 0.3, 0.4, 0.5],
"embedding2": [0.6, 0.7, 0.8, 0.9, 1.0]
}
}
metadata (array)
Specify which metadata fields to include in the response. Valid values must come from metadataFields in GET /v1/retrieve/definition.
Example:
{
"text": "clinical studies",
"metadata": ["labels", "entities"]
}
If unknown field names are requested, the endpoint returns a warning listing invalid names and still returns values for valid requested fields.
Response format
Success response
HTTP Status: 200 OK
Body:
{
"matches": [
{
"id": "/pubmed/39702603.xml",
"labels": ["medical-data", "pubmed"],
"score": {
"fulltext": 7680,
"vectors": {}
},
"extractedText": {
"vectorExtractedText": null,
"fulltextExtractedText": null
}
},
...
],
"totalMatches": 42
}
Response fields:
The response is an object with these top-level fields:
matchesโarray(required): Array of result objects, ordered by relevance.totalMatchesโinteger(optional): Total number of documents in the database that match the search query, regardless of thetopklimit. Present for text-based searches; absent for vector-only queries (when onlyvectorsis provided). Use this to determine whethertopkneeds to be increased to capture more results.warningsโarray of strings(optional): Warning messages generated during query processing, including filter configuration issues, non-emptyentitiesorrelationsparameters, and unknownmetadatafield names. Absent when there are no warnings.
Each match object in the matches array contains:
idโstring(required): The document URI/identifier.labelsโarray of strings(required): Collections assigned to the matching document.scoreโobject(required): Relevance scores for the document.fulltextโnumber(required): Full-text search relevance score; higher is better.vectorsโobject(required): Vector similarity scores keyed by embedding name.
extractedTextโobject(required): Text extractions from the document.vectorExtractedTextโobject or null(required): For vector search results, an object keyed by vector column name. Each value maps non-system Optic row column names to values;nullfor full-text-only results.fulltextExtractedTextโarray of objects or null(required): Text extracted through configured XPath expressions. Each object hastextandxpathSourceproperties.nullfor vector-only results, or an empty array when noextractionXPathsare configured. See retrieveConfig.json.
metadataPropertiesโobject(optional): Extracted metadata field values keyed by field name. Present only when themetadataparameter was provided, and only for full-text search results.chunkDataโobject(optional): Present only for a pre-processed RAG chunk identified by thechunksconfiguration inretrieveConfig.json. Absent for non-chunk documents.chunkCollectionโstring(required): The MarkLogic Server collection that identified this document as a chunk.parentUriโstring(optional): URI of the original source document. Omitted if the configuredchunkIdRegexlacks capture group 1.chunkNumberโinteger(optional): Zero-based ordinal position within the parent document. Omitted if the configuredchunkIdRegexlacks capture group 2.totalChunksโinteger(optional): Total number of chunks detected for the same parent document. Omitted when the total cannot be derived.previousChunkUriโstring(optional): URI of the immediately previous chunk. Omitted for first chunks or when the neighbor cannot be derived or found.nextChunkUriโstring(optional): URI of the immediately next chunk. Omitted for last chunks or when the neighbor cannot be derived or found.extractedTextโarray of strings(required): Text extracted from the chunk through theextractionXPathsconfigured in the matchingchunksentry ofretrieveConfig.json.
Empty results
If no documents match the search criteria, the matches array will be empty:
{
"matches": []
}
Error responses
Error responses generally have this response body:
{
"errorResponse": {
"statusCode": 400,
"status": "Bad Request",
"message": "Invalid parameter format"
}
}
The errorResponse object always contains statusCode (the numeric HTTP status), status (the HTTP reason phrase), and message (a human-readable description).
400โ Invalid request format or parameters.- Status:
Bad Request - Message:
Invalid parameter format
- Status:
401โ Missing or invalid authentication.- Status:
Unauthorized - Message:
Authentication required
- Status:
500โ Server-side error.- Status:
Internal Server Error - Message:
Search execution failed
- Status:
Search behavior
Filter combination logic
- Multiple filters use AND logic (all must match)
- Labels (collections) are combined with AND logic for multiple collections
- Filters and labels are combined together (document must satisfy both)
Result ordering
Results in the matches array are ordered by:
- Relevance score - Higher
score.fulltextvalues appear first - Vector similarity - When vectors are provided,
score.vectorsinfluences ranking - Text match quality - Exact matches rank higher than partial matches
The matches array contains results in descending order of relevance, with the most relevant documents first.
Performance considerations
- Text-only searches: Very fast, uses MarkLogic Server's optimized indexes
- Vector searches: May be slower for large embedding dimensions
- Multiple filters: Each additional filter adds processing overhead
- Large topk values: May impact performance, use reasonable limits