THIS METHOD IS DEPRECATED; use /v1/search and /v1/qbe instead. Query the database based on the value of a JSON key, XML element, or XML element attribute.
Request Headers | |
---|---|
Accept* |
The expected MIME type of the response. Accepted values:
application/json or application/XML .
Default: XML.
|
Response Headers | |
---|---|
Content-Type |
The MIME type of the data in the response. The results will be in
either XML or JSON, depending upon the value of the format
parameter or the Accept header.
|
MarkLogic Server returns a 200 (OK) status, whether there are
search matches or not. If XML output is requested, the response body
contains a search:reponse
node. If JSON output is requested,
the response body contains a JSON map with keys that closely correspond
to the search:response
elements.
rest-reader
role, or the
following privilege:
http://marklogic.com/xdmp/privileges/rest-reader
Use the key
and value
parameters to query
JSON documents inserted into the database using the /documents
service. Use the element
and attribute
parameters with value
to search XML documents.
The expected response type can be specified using either the
format
parameter or Accept
header. One or
the other must be supplied. If both are supplied and are different,
the format
parameter takes precedence.
Query options must be pre-installed using the
/config/query service
. If no query options are specified
with the options
parameter, the global default options are
used.
For more details, see Querying Documents and Metadata in the REST Application Developer's Guide.
$ curl --anyauth --user user:password -X GET -i \ 'http://localhost:8000/v1/keyvalue?element=TITLE&value=Cymbeline' ==> A search:result for all documents occurrences of a TITLE element with a value of "Cymbeline". MarkLogic Server returns the following: Server: MarkLogic Content-Type: text/plain; charset=UTF-8 Content-Length: 31 Connection: close HTTP/1.1 200 OK Content-type: application/xml Server: MarkLogic Content-Length: 858 Connection: close <search:response total="1" start="1" page-length="10" xmlns="" xmlns:search="http://marklogic.com/appservices/search"> <search:result index="1" uri="/shakespeare/plays/cymbelin.xml" path="fn:doc("/shakespeare/plays/cymbelin.xml")" score="17920" confidence="0.336069" fitness="0.336069"> <search:snippet> <search:match path="fn:doc("/shakespeare/plays/cymbelin.xml")/PLAY"> <search:highlight>Cymbeline</search:highlight> </search:match> </search:snippet> </search:result> <search:metrics> <search:query-resolution-time>PT0.015515S</search:query-resolution-time> <search:facet-resolution-time>PT0.000118S</search:facet-resolution-time> <search:snippet-resolution-time>PT0.027884S</search:snippet-resolution-time> <search:total-time>PT0.044953S</search:total-time> </search:metrics> </search:response>
$ curl --anyauth --user user:password -X GET -i \ -H "Accept: application/json" \ 'http://localhost:8000/v1/keyvalue?element=TITLE&value=Cymbeline' ==> A search:result for all documents occurrences of a TITLE element with a value of "Cymbeline". MarkLogic Server returns the following (whitespace added for clarity): Server: MarkLogic Content-Type: text/plain; charset=UTF-8 Content-Length: 31 Connection: close HTTP/1.1 200 OK Content-type: application/json Server: MarkLogic Content-Length: 500 Connection: close { "snippet-format": "snippet", "total": 1, "start": 1, "page-length": 10, "results": [ { "index": 1, "uri": "/shakespeare/plays/cymbelin.xml", "path": "fn:doc(\"/shakespeare/plays/cymbelin.xml\")", "score": 15360, "confidence": 0.338445, "fitness": 0.338445, "matches": [ { "path": "fn:doc(\"/shakespeare/plays/cymbelin.xml\")/PLAY", "match-text": [ "\n", { "highlight": "Cymbeline" }, "\n" ] } ] } ], "metrics": { "query-resolution-time": "PT0.009748S", "facet-resolution-time": "PT0.000087S", "snippet-resolution-time": "PT0.022979S", "total-time": "PT0.033092S" } }
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.