Skip to main content

Administrating MarkLogic Server

Query Assignment Policy

The query assignment policy, like the range assignment policy, is designed for use with Tiered Storage Query Partitions described in Query Partitions. The query assignment policy works in a similar manner as the range assignment policy. However, rather than using lower and upper bound values to determine which documents are in a partition, the query assignment policy uses a query to determine which documents are in a partition. Users have the flexibility to use multiple keys and use different conditions for different types of documents.

With range assignment policy, the boundaries are fixed. However, you might want to rebalance the documents based on the difference between the entry time and the current time. When a range query compares a dateTime with duration, it becomes an age query.

For example, this query will match documents where "LastModified" is within past year:

cts:element-range-query(
     xs:QName("LastModified"), 
     ">=",
     xs:yearMonthDuration("P1Y"))

When creating a query partition, you assign it a partition number. Unlike range partitions, queries set for partitions using the query assignment policy can have “overlaps,” but, in the event of an overlap, the partition with lower number is selected before partitions with higher numbers.

Note

As is the case with range assignment policy, you should always define a default partition when configuring the query assignment policy.

Here is an example of a query assignment policy setup. MD and AD are elements in the documents:

Partition Name

Tier1

Tier2

Tier3

Tier4

Partition Number

1

2

3

4

Query

(Termination eq yes) OR (Source eq "Hiring" AND MD > 30 days) OR (Source eq "CFO" AND MD > 30 days)

(Source eq "Hiring" AND MD <= 30 days AND MD > 1 year) OR (Source eq "CFO" AND MD <= 30 days AND MD > 60 days) OR (Source eq "Benefits" AND AD > 1 year)

(Source eq "Hiring" AND MD <= 1 year AND MD > 3 years) OR (Source eq "CFO" AND MD <= 60 days) OR (Source eq "Benefits" AND AD <= 1 year)

(Source eq "Hiring" AND MD <= 3 years)

Default

Yes

No

No

No

There is only one cts:query per partition.

When the query assignment policy is used, these rules are used for document insert:

  • The partition number is used for priority. If there is more than one query that match the document, the partition with the lower partition number is used.

  • If none of the queries matches the document, the default partition is used.

  • If there is no default partition, the forests without a partition number are used.

  • Otherwise, it is an error.

Among the forests in a partition, the documents are assigned to the forests using the statistical assignment policy.

The query requires the proper indexes to be configured in the database. The complexity of the query affects the performance of insert and rebalancing. Therefore slow queries such as those with wildcard matching are not recommended.

See Setting the Query Assignment Policy for the Query Partition for details on how to set the query assignment policy.