Setting the Query Assignment Policy for the Query Partition
After creating a query partition, you can use the POST:/manage/v2/databases/{id|name}/partition-queries
REST resource address to assign to it a query assignment policy, as described in Query Assignment Policy.
Note
Any indexes required for the query must be created before creating the query partition.
A query assignment policy in XML takes the form:
<partition-query-properties xmlns="http://marklogic.com/manage/partition-query/properties">
<partition-number>1</partition-number>
<query>
....cts:query.....
</query>
</partition-query-properties>
A query assignment policy in JSON takes the form:
{
"partition-number": "1",
"query": {
....cts.query.....
}
}
The search portion is a cts:query
expression, as described in Composing cts:query Expressions in the Search Developer’s Guide. There can be only one cts:query
per partition.
The query requires the proper index to be configured in the database. The complexity of the query affects the performance of insert and rebalancing. Therefore slow query like wildcard matching is not recommended.
For example to direct all documents that have either the word “Manager” or “Engineer” in them to the tier1
query partition created above, you would do the following:
$ cat query1.xml <partition-query-properties xmlns="http://marklogic.com/manage/partition-query/properties"> <partition-number>1</partition-number> <query> <cts:or-query xmlns:cts="http://marklogic.com/cts"> <cts:word-query> <cts:text xml:lang="en">Manager</cts:text> </cts:word-query> <cts:word-query> <cts:text xml:lang="en">Engineer</cts:text> </cts:word-query> </cts:or-query> </query> </partition-query-properties>
curl -X POST --anyauth -u admin:admin \ -H "Content-Type:application/xml" -d @query1.xml \ http://gordon-1:8002/manage/v2/databases/Schemas/partition-queries
The following query assignment policy will match documents where "LastModified" is within the last year:
<partition-query-properties xmlns="http://marklogic.com/manage/partition-query/properties"> <partition-number>1</partition-number> <query> <cts:element-range-query operator=">=" xmlns:cts="http://marklogic.com/cts"> <cts:element>LastModified</cts:element> <cts:value type="xs:yearMonthDuration">P1Y</cts:value> </cts:element-range-query> </query> </partition-query-properties>
The same query assignment policy in JSON:
{ "partition-number": 1, "query": { "element-range-query": { "operator": ">=", "element": "LastModified", "value": { "type": "xs:yearMonthDuration", "val": "P1Y" } } } }
For queries against a dateTime index, when $value
is an xs:dayTimeDuration
or xs:yearMonthDuration
, the query is executed as an age query. $value
is subtracted from fn:current-dateTime()
to create a xs:dateTime
used in the query. If there is more than one item in $value
, they must all be the same type.
For example, given a dateTime
index on element startDateTime
, queries cts:element-range-query(xs:QName ("startDateTime"), ">", xs:dayTimeDuration("P1D"))
and cts:element-range-query(xs:QName ("startDateTime"), ">", fn:current-dateTime() - xs:dayTimeDuration("P1D"))
are the same: both match values within the last day.