Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elasticsearch: keep path from base URI #3042

Merged
merged 4 commits into from
Dec 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package akka.stream.alpakka.elasticsearch.impl

import akka.annotation.InternalApi
import akka.http.scaladsl.HttpExt
import akka.http.scaladsl.model.Uri.Path
import akka.http.scaladsl.model._
import akka.http.scaladsl.unmarshalling.Unmarshal
import akka.stream.alpakka.elasticsearch._
Expand Down Expand Up @@ -71,15 +70,17 @@ private[elasticsearch] final class ElasticsearchSimpleFlowStage[T, C](
override def onPull(): Unit = tryPull()

override def onPush(): Unit = {
val endpoint = if (settings.allowExplicitIndex) "/_bulk" else s"/${elasticsearchParams.indexName}/_bulk"
val endpoint =
if (settings.allowExplicitIndex) baseUri.path ?/ "_bulk"
else baseUri.path ?/ elasticsearchParams.indexName / "_bulk"
val (messages, resultsPassthrough) = grab(in)
inflight = true
val json: String = restApi.toJson(messages)

log.debug("Posting data to Elasticsearch: {}", json)

if (json.nonEmpty) {
val uri = baseUri.withPath(Path(endpoint))
val uri = baseUri.withPath(endpoint)
val request = HttpRequest(HttpMethods.POST)
.withUri(uri)
.withEntity(HttpEntity(NDJsonProtocol.`application/x-ndjson`, json))
Expand Down