I am looking for an api to get specific section of document returned. For example from a document
<user>
<firstname> name </firstname>
<lastname> last name </lastname>
</user>
I only need <firstname>
data. How can I get that?
I am looking for an api to get specific section of document returned. For example from a document
<user>
<firstname> name </firstname>
<lastname> last name </lastname>
</user>
I only need <firstname>
data. How can I get that?
If you want to run a search and get that particular element back with each document result, you can use extract-document-data
in your query options. Use something like this for the body of a POST request to /v1/search:
<search xmlns="http://marklogic.com/appservices/search">
<qtext>your string query</qtext>
<options>
<extract-document-data selected=value>
<extract-path>/user/lastname</extract-path>
</extract-document-data>
</options>
</search>
Once you get that doing what you want, you can store the query options in MarkLogic rather than including them in every search request.
If you are just looking for the value, rather than including that value in search results, I would use /v1/values/[name] instead. You'll need to configure a range index on firstname
.
You should use "Transforming Content during Retrieval" as described in https://docs.marklogic.com/guide/rest-dev/documents#id_43943