Include document extracts in search results
- Last Updated: May 5, 2026
- 2 minute read
- MarkLogic Server
- Documentation
By default, /v1/search results do not include data from matching documents. Include this information by using the extract-document-data property in the query options of the application.
Matching document
Consider a matching document with this structure:
{ "envelope": {
"entityType": "person",
"id": 1001,
"firstName": "Nerta",
"lastName": "Hallwood",
"title": "Marketing Manager"
}
}
JSON query options
This example uses JSON query options and includes data from the /envelope path in the document for each result. The extract-path property takes an XPath expression that selects the document content to include in the results:
{
"options": {
"extract-document-data": {
"selected": "include",
"extract-path": "/envelope"
}
}
}
XML query options
XML can also be used to include document content using query options:
<?xml version="1.0" encoding="UTF-8"?>
<options>
<extract-document-data selected="include">
<extract-path>/envelope</extract-path>
</extract-document-data>
</options>
Search results
When query options are included, these search results are returned:
Note:
Notice that the extracted property contains matching document information.
{
"snippet-format": "snippet",
"total": 1,
"start": 1,
"page-length": 10,
"selected": "include",
"results": [
{
"index": 1,
"uri": "/person/1001.json",
"path": "fn:doc(\"/person/1001.json\")",
"score": 2816,
"confidence": 0.2636895,
"fitness": 0.2763854,
"href": "/v1/documents?uri=%2Fperson%2F1001.json",
"mimetype": "application/json",
"format": "json",
"matches": [
{
"path": "fn:doc(\"/person/1001.json\")/envelope/text(\"entityType\")",
"match-text": [
{
"highlight": "person"
}
]
}
],
"extracted": {
"kind": "array",
"content": [
{
"envelope": {
"entityType": "person",
"id": 1001,
"firstName": "Nerta",
"lastName": "Hallwood",
"title": "Marketing Manager",
}
}
]
}
}
],
"qtext": "person",
"metrics": {
"query-resolution-time": "PT0.001205S",
"snippet-resolution-time": "PT0.001033S",
"extract-resolution-time": "PT0.000818S",
"total-time": "PT0.22377S"
}
}
When document extract information is included in search results, the widgets displaying the results have access to document information. See extract-document-data for more details.
Note:
To include all of the matching documents in search results, include an extract-document-data property or element without the extract-path property or element. This can be useful when a JSON document does not have a single root property.