Skip to content

Commit

Permalink
Change reindex all indexing order, add logging to bulk indexing
Browse files Browse the repository at this point in the history
Co-authored-by: Karen Shaw <[email protected]>
Co-authored-by: Michael B. Klein <[email protected]>
  • Loading branch information
3 people committed Aug 16, 2024
1 parent ae95905 commit 30f0b41
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/lib/meadow/data/indexer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule Meadow.Data.Indexer do
end

def reindex_all(version) do
reindex_all(version, [FileSet, Work, Collection])
reindex_all(version, [Collection, Work, FileSet])
end

def reindex_all(version, schemas) when is_list(schemas) do
Expand Down
24 changes: 22 additions & 2 deletions app/lib/meadow/search/bulk.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ defmodule Meadow.Search.Bulk do
Bulk indexing operations for search
"""

use Meadow.Utils.Logging
require Logger

alias Meadow.Search.Config, as: SearchConfig
alias Meadow.Search.HTTP

Expand Down Expand Up @@ -35,7 +38,24 @@ defmodule Meadow.Search.Bulk do
do: :timer.sleep(wait_interval)

defp upload_batch(docs, index) do
bulk_document = docs |> Enum.join("\n")
HTTP.post("/#{index}/_bulk", bulk_document <> "\n")
with_log_metadata module: __MODULE__, index: index do
bulk_document = docs |> Enum.join("\n")

Logger.info("Uploading batch of #{Enum.count(docs)} documents to #{index}")

case HTTP.post("/#{index}/_bulk", bulk_document <> "\n") do
{:ok, %{status_code: status} = response} ->
Logger.info("Bulk upload status: #{status}")
{:ok, response}

{:retry, response} ->
Logger.warn("Bulk upload retrying")
{:retry, response}

{:error, error} ->
Logger.error("Bulk upload failed: #{inspect(error)}")
{:error, error}
end
end
end
end

0 comments on commit 30f0b41

Please sign in to comment.