get method Null safety

Future<IndexSnapshot> get(
  1. {int? size,
  2. bool onlyIds = false}
)

Implementation

Future<IndexSnapshot> get({int? size, bool onlyIds: false}) async {
  try {
    Map<String, dynamic> data = compoundBody;
    if (onlyIds) data["stored_fields"] = [];
    if (size != null) data["size"] = size;
    final response = await client.post("/$index/_search", data: data);
    final docs = (response["hits"]["hits"] as List)
        .map((doc) => Document.fromJson(doc))
        .toList();
    return IndexSnapshot(docs, success: true);
  } catch (e) {
    return IndexSnapshot([], success: false, reason: e.toString());
  }
}