Get()
This operation issues a query with primary keys and returns a list of records.
Status Get(const GetRequest& request, GetResponse& response)
Request Syntax
auto request = GetRequest()
.WithDatabaseName(db_name)
.WithCollectionName(collection_name)
.WithPartitionNames(partition_names)
.WithOutputFields(output_field_names)
.WithConsistencyLevel(consistency_level)
.WithIDs(id_array);
REQUEST METHODS:
WithDatabaseName(const std::string& db_name)Sets the target database name. The default database applies if it is empty.
WithCollectionName(const std::string& collection_name)Sets the name of the collection.
WithPartitionNames(std::set<std::string>&& partition_names)Sets the names of the partitions. If it is empty, the default partition applies.
AddPartitionName(const std::string& partition_name)Adds a partition name.
WithOutputFields(std::set<std::string>&& output_field_names)Sets the output field names.
AddOutputField(const std::string& output_field)Adds an output field.
WithConsistencyLevel(ConsistencyLevel consistency_level)Sets the consistency level.
WithIDs(std::vector<int64_t>&& id_array)Sets an ID array.
RETURNS:
Status with GetResponse
Check status.IsOk() to confirm success.
EXCEPTIONS:
StatusCode
Check
status.Code()andstatus.Message()for error details.
Example
#include "milvus/MilvusClientV2.h"
auto client = milvus::MilvusClientV2::Create();
milvus::ConnectParam connect_param{"http://localhost:19530", "root:Milvus"};
auto status = client->Connect(connect_param);
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
std::vector<int64_t> ids = {5, 1, 10, 8};
auto request = milvus::GetRequest()
.WithCollectionName(collection_name)
.WithIDs(std::move(ids))
.AddOutputField(field_vector);
milvus::GetResponse response;
status = client->Get(request, response);
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
auto query_results = response.Results();
milvus::EntityRows output_rows;
status = query_results.OutputRows(output_rows);
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
std::cout << "Get results:" << std::endl;
for (const auto& row : output_rows) {
std::cout << "\t" << row << std::endl;
}