cluster clause

更新时间:
复制 MD 格式

Clause description

A cluster clause is optional. You can use the cluster clause to specify the partitions in a cluster in which you want to perform a query.

Syntax

Specify partition field values

{
  "cluster" : {  
    "hash_field" : []
  }
}

The hash_field parameter specifies the value of the sharding field. You can specify multiple values. During a query, the system hashes these values to calculate the corresponding shard IDs and then retrieves the data. Examples:

# Retrieve data from shards that correspond to the hash field content "123" and "456".
{
  "cluster" : {  
    "hash_field" : ["123", "456"]
  }
}

# Retrieve data from the shard that corresponds to the hash field content "abc".
{
  "cluster" : {  
    "hash_field" : ["abc"]
  }
}

Query by Shard ID

{
  "cluster" : {  
    "part_ids" : []
  }
}

If you know the shard ID, you can specify it directly to retrieve data. You can obtain shard IDs from query results. The total range for shard IDs is [0, 65535]. For example, if a cluster has two shards, their ID ranges are [0, 32767] and [32768, 65535]. The system retrieves data from a shard if the ID you provide falls within that shard's ID range. Examples:

# Retrieve data from shards that correspond to the IDs 123 and 8790.
{
  "cluster" : {
    "part_ids" : [123,8790]
  }
}

Usage notes

  • You can specify only one of the hash_field and part_ids parameters in a cluster clause.