From 1a76cc484cf2bbb1cdc29876587fcc7b72a0341c Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Fri, 14 Aug 2020 01:24:14 -0400 Subject: [PATCH] flatten gallery fields; preparation for removal of nested documents from index --- .github/workflows/elixir.yml | 2 +- docker-compose.yml | 2 +- index/images.mk | 4 +++- lib/philomena/images/elasticsearch_index.ex | 4 ++++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml index 5fe84d75..eaca9390 100644 --- a/.github/workflows/elixir.yml +++ b/.github/workflows/elixir.yml @@ -21,7 +21,7 @@ jobs: --health-timeout 5s --health-retries 5 elasticsearch: - image: elasticsearch:7.6.2 + image: elasticsearch:7.8.1 ports: ['9200:9200'] redis: image: redis:5.0.9 diff --git a/docker-compose.yml b/docker-compose.yml index 9430c01f..0feec3f2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -30,7 +30,7 @@ services: driver: "none" elasticsearch: - image: elasticsearch:7.6.2 + image: elasticsearch:7.8.1 volumes: - elastic_data:/var/lib/elasticsearch logging: diff --git a/index/images.mk b/index/images.mk index cddef990..35466379 100644 --- a/index/images.mk +++ b/index/images.mk @@ -63,7 +63,9 @@ deleters: image_search_json galleries: image_search_json psql $(DATABASE) -v ON_ERROR_STOP=1 <<-SQL - insert into temp_images.image_search_json (image_id, object) select gi.image_id, jsonb_build_object('gallery_interactions', jsonb_agg(jsonb_build_object('gallery_id', gi.gallery_id, 'position', gi.position))) from gallery_interactions gi group by image_id; + insert into temp_images.image_search_json (image_id, object) select gi.image_id, jsonb_build_object('gallery_interactions', jsonb_agg(jsonb_build_object('id', gi.gallery_id, 'position', gi.position))) from gallery_interactions gi group by image_id; + insert into temp_images.image_search_json (image_id, object) select gi.image_id, jsonb_build_object('gallery_id', jsonb_agg(gi.gallery_id)) from gallery_interactions gi group by image_id; + insert into temp_images.image_search_json (image_id, object) select gi.image_id, jsonb_build_object('gallery_position', jsonb_object_agg(gi.gallery_id, gi.position)) from gallery_interactions gi group by image_id; SQL tags: image_search_json diff --git a/lib/philomena/images/elasticsearch_index.ex b/lib/philomena/images/elasticsearch_index.ex index 193bab3d..2a56d3bc 100644 --- a/lib/philomena/images/elasticsearch_index.ex +++ b/lib/philomena/images/elasticsearch_index.ex @@ -73,6 +73,8 @@ defmodule Philomena.Images.ElasticsearchIndex do position: %{type: "integer"} } }, + gallery_id: %{type: "keyword"}, + gallery_position: %{type: "object", enabled: false}, namespaced_tags: %{ properties: %{ name: %{type: "keyword"}, @@ -133,6 +135,8 @@ defmodule Philomena.Images.ElasticsearchIndex do namespaced_tags: %{ name: image.tags |> Enum.flat_map(&([&1] ++ &1.aliases)) |> Enum.map(& &1.name) }, + gallery_id: Enum.map(image.gallery_interactions, & &1.gallery_id), + gallery_position: Map.new(image.gallery_interactions, &{&1.gallery_id, &1.position}), favourited_by_users: image.favers |> Enum.map(&String.downcase(&1.name)), hidden_by_users: image.hiders |> Enum.map(&String.downcase(&1.name)), upvoters: image.upvoters |> Enum.map(&String.downcase(&1.name)),