Bernhard
09/16/2026, 1:12 PMephemient
09/16/2026, 1:22 PMBernhard
09/16/2026, 1:22 PMBernhard
09/16/2026, 1:23 PMephemient
09/16/2026, 1:32 PMcall.respondTextWriter {
results.collect {
appendLine(Json.encodeToString(it))Bernhard
09/16/2026, 1:33 PMBernhard
09/16/2026, 1:33 PMBernhard
09/16/2026, 1:34 PMephemient
09/16/2026, 1:38 PMBernhard
09/16/2026, 1:45 PMBernhard
09/16/2026, 1:45 PMsuspend fun <I : Any> indexMany(items: Iterable<I>, type: KType) {
<http://client.post|client.post>(config.baseUrl) {
url {
appendPathSegments("api", "v1", "collections", config.collection, "documents", "import")
}
headers {
append("X-BI-API-KEY", config.apiKey)
}
val serializer = serializer(type)
val body = ChannelWriterContent(
body = {
var first = true
items.forEach {
if (!first) {
writeStringUtf8("\n")
}
writeStringUtf8(json.encodeToString(serializer, it))
first = false
}
},
contentType = ContentType("application", "x-ndjson"),
)
setBody(body)
contentType(ContentType.Application.Json)
}
}ephemient
09/16/2026, 1:53 PMfor (item in items) {
writeStringUtf8(json.encodeToString(serializer, item))
writeStringUtf8("\n")
}
without firstBernhard
09/16/2026, 1:53 PMBernhard
09/16/2026, 1:53 PMephemient
09/16/2026, 1:54 PM\n is seen as a line terminator, not a record separator
2. even if it weren't, ndjson ignores empty lines