Is it possible to fetch all the unique values of a json-property from multiple documents in a collection using the Marklogic Java Client API?
For example, if there are 3 "MyDocument" type documents with the property "myProperty" as follows:
MyDocument1.json
{
"myProperty":"val1"
}
MyDocument2.json
{
"myProperty":"val1"
}
MyDocument3.json
{
"myProperty":"val2"
}
The goal is to retrieve all unique values for "myProperty", which would be "val1" and "val2".
Additionally, can the documents be grouped based on these distinct values? For instance:
{
"val1": [
{
"myProperty":"val1"
},
{
"myProperty":"val1"
}
],
"val2": [
{
"myProperty":"val2"
}
]
}
Any assistance or guidance in the right direction would be greatly appreciated. Thank you!
Update:
I was able to achieve the desired result using XQuery in qConsole. Here's what I did:
xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy";
let $options :=
<options xmlns="http://marklogic.com/appservices/search">
<values name="myProperty">
<range type="string" facet="true">
<json-property>myProperty</json-property>
</range>
</values>
</options>
return search:values("myProperty", $options)
The result obtained was:
<search:values-response name="myProperty" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:search="http://marklogic.com/appservices/search">
<search:distinct-value frequency="2">val1</search:distinct-value>
<search:distinct-value frequency="1">val2</search:distinct-value>
</search:values>
Now the aim is to accomplish this using the Java Client API.