Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Count docs in index when loading sample data (#2491)

Dhruv Bhanushali032d7596f2ea
diff --git a/docker/es/justfile b/docker/es/justfile
index be9cfa42d..5c91f3e08 100644
--- a/docker/es/justfile
+++ b/docker/es/justfile
@@ -26,19 +26,45 @@ NO_COLOR := "\\033[0m"
'"$(just docker/es/health {{ host }})" != "200"' \
"Waiting for Elasticsearch to be healthy..."
-@check-index index="image" dest="":
+########
+# cURL #
+########
+
+# Make a cURL request to the given path
+_curl path:
-curl \
-s \
-H 'Accept: application/json' \
- 'http://localhost:50292/_cat/indices/{{ index }}' \
- | grep -o "{{ (if dest == "" { index } else { dest }) }}" \
+ 'http://localhost:50292/{{ path }}'
+
+# Count the number of times the given string appears in the response
+_curl-wc path search:
+ just _curl {{ path }} \
+ | grep -o "{{ search }}" \
| wc -l \
| xargs
-# Wait for the media to be indexed in Elasticsearch
+# Check that the given index exists
+@check-index index="image" dest="":
+ just _curl-wc "_cat/indices/{{ index }}" "{{ (if dest == "" { index } else { dest }) }}"
+
+# Wait for the index to be present in Elasticsearch
@wait-for-index index="image" dest="":
# The just command on the second line is executed in the context of the
# root directory and so must be prefixed with `docker/es/`.
just ../../_loop \
'"$(just docker/es/check-index {{ index }} {{ dest }})" != "1"' \
"Waiting for index '{{ index }}' to be ready..."
+
+# Check that the given index has the given number of docs
+@check-count index="image" count="5000":
+ just _curl-wc "{{ index }}/_count" '\"count\":{{ count }}'
+
+# Wait for the index to have the given number of docs
+@wait-for-count index="image" count="5000":
+ # The just command on the second line is executed in the context of the
+ # root directory and so must be prefixed with `docker/es/`.
+ just ../../_loop \
+ '"$(just docker/es/check-count {{ index }} {{ count }})" != "1"' \
+ "Waiting for index '{{ index }}' to have {{ count }} docs..." \
+ "10s"
diff --git a/load_sample_data.sh b/load_sample_data.sh
index e9815d875..bc55042ae 100755
--- a/load_sample_data.sh
+++ b/load_sample_data.sh
@@ -77,8 +77,10 @@ docker-compose exec -T "$DB_SERVICE_NAME" bash -c "psql <<-EOF
# Ingest and index the data
just ingestion_server/ingest-upstream "audio" "init"
just docker/es/wait-for-index "audio-init"
+just docker/es/wait-for-count "audio-init"
just ingestion_server/promote "audio" "init" "audio"
just docker/es/wait-for-index "audio"
+just docker/es/wait-for-count "audio"
just ingestion_server/create-and-populate-filtered-index "audio" "init"
just docker/es/wait-for-index "audio-init-filtered"
just ingestion_server/point-alias "audio" "init-filtered" "audio-filtered"
@@ -95,8 +97,10 @@ while true; do
done
set -e
+just docker/es/wait-for-count "image-init"
just ingestion_server/promote "image" "init" "image"
just docker/es/wait-for-index "image"
+just docker/es/wait-for-count "image"
just ingestion_server/create-and-populate-filtered-index "image" "init"
just docker/es/wait-for-index "image-init-filtered"
just ingestion_server/point-alias "image" "init-filtered" "image-filtered"