From b2352c1d23f7a08f917b9084bb8e88f2026ffd6f Mon Sep 17 00:00:00 2001 From: redblackblossom Date: Wed, 31 Jul 2024 15:56:58 +0900 Subject: [PATCH 01/18] =?UTF-8?q?feat=20:=20es=20=EC=9D=B8=EB=8D=B1?= =?UTF-8?q?=EC=8A=A4=20json=20=ED=8C=8C=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../elasticsearch/index/face_vectors.json | 31 +++++++++++++++++++ .../photo/elasticsearch/index/photos_es.json | 31 +++++++++++++++++++ .../index/sample_photo_vectors.json | 21 +++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/face_vectors.json create mode 100644 src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/photos_es.json create mode 100644 src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/sample_photo_vectors.json diff --git a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/face_vectors.json b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/face_vectors.json new file mode 100644 index 0000000..cfd7672 --- /dev/null +++ b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/face_vectors.json @@ -0,0 +1,31 @@ +{ + "settings" : { + "index" :{ + "number_of_shards" : 5, + "number_of_replicas" : 1 + } + }, + "mappings" : { + "_routing": { + "required" : true + }, + "properties" : { + "shareGroupId" : { + "type" : "long" + }, + "keyValue" : { + "type" : "keyword" + }, + "createdAt" : { + "type" : "date", + "format" : "basic_ordinal_date_time_no_millis" + }, + "faceVector" : { + "type": "dense_vector", + "dims": 128, + "index": true, + "similarity" : "dot_product" + } + } + } +} \ No newline at end of file diff --git a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/photos_es.json b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/photos_es.json new file mode 100644 index 0000000..b961c6b --- /dev/null +++ b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/photos_es.json @@ -0,0 +1,31 @@ +{ + "settings" : { + "index" :{ + "number_of_shards" : 2, + "number_of_replicas" : 2 + } + }, + "mappings" : { + "_routing": { + "required" : true + }, + "properties" : { + "shareGroupId" : { + "type" : "long" + }, + "keyValue" : { + "type" : "keyword" + }, + "createdAt" : { + "type" : "date", + "format" : "basic_ordinal_date_time_no_millis" + }, + "faceTag" : { + "type" : "long" + }, + "downloadTag" : { + "type" : "long" + } + } + } +} \ No newline at end of file diff --git a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/sample_photo_vectors.json b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/sample_photo_vectors.json new file mode 100644 index 0000000..5a7dcdc --- /dev/null +++ b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/sample_photo_vectors.json @@ -0,0 +1,21 @@ +{ + "settings" : { + "index" :{ + "number_of_shards" : 3, + "number_of_replicas" : 1 + } + }, + "mappings" : { + "properties" : { + "memberId" : { + "type" : "long" + }, + "faceVector" : { + "type": "dense_vector", + "dims": 128, + "index": true, + "similarity" : "dot_product" + } + } + } +} \ No newline at end of file From 8916d45309d11ba7518c13233baa08fbcd5e81fb Mon Sep 17 00:00:00 2001 From: redblackblossom Date: Wed, 31 Jul 2024 18:46:44 +0900 Subject: [PATCH 02/18] =?UTF-8?q?feat=20:=20Elasticsearch=20=EC=9D=98?= =?UTF-8?q?=EC=A1=B4=EC=84=B1=EA=B3=BC=20configuration=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 4 ++++ .../naoman/global/config/ElasticsearchConfig.java | 15 +++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/main/java/com/umc/naoman/global/config/ElasticsearchConfig.java diff --git a/build.gradle b/build.gradle index 1d8ccbe..34e74bc 100644 --- a/build.gradle +++ b/build.gradle @@ -61,6 +61,10 @@ dependencies { implementation platform("io.awspring.cloud:spring-cloud-aws-dependencies:3.0.0") implementation 'io.awspring.cloud:spring-cloud-aws-starter-s3' implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' + + //elasticsearch + implementation 'org.springframework.data:spring-data-elasticsearch:' + implementation 'co.elastic.clients:elasticsearch-java:' } tasks.named('test') { diff --git a/src/main/java/com/umc/naoman/global/config/ElasticsearchConfig.java b/src/main/java/com/umc/naoman/global/config/ElasticsearchConfig.java new file mode 100644 index 0000000..3150053 --- /dev/null +++ b/src/main/java/com/umc/naoman/global/config/ElasticsearchConfig.java @@ -0,0 +1,15 @@ +package com.umc.naoman.global.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.data.elasticsearch.client.ClientConfiguration; +import org.springframework.data.elasticsearch.client.elc.ElasticsearchConfiguration; + +@Configuration +public class ElasticsearchConfig extends ElasticsearchConfiguration { + @Override + public ClientConfiguration clientConfiguration() { + return ClientConfiguration.builder() + .connectedTo("localhost:9200") + .build(); + } +} From 4493ddd7df6961319e8060a24c3819f009630070 Mon Sep 17 00:00:00 2001 From: redblackblossom Date: Wed, 31 Jul 2024 19:10:48 +0900 Subject: [PATCH 03/18] =?UTF-8?q?feat=20:=20Elasticsearch=20Document,=20Re?= =?UTF-8?q?pository=20=EC=B4=88=EC=95=88=20=EA=B0=9C=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../elasticsearch/document/FaceVector.java | 30 +++++++++++++++++ .../photo/elasticsearch/document/PhotoEs.java | 32 +++++++++++++++++++ .../document/SamplePhotoVector.java | 26 +++++++++++++++ .../repository/FaceVectorRepository.java | 9 ++++++ .../repository/PhotoEsRepository.java | 9 ++++++ .../SamplePhotoVectorRepository.java | 9 ++++++ 6 files changed, 115 insertions(+) create mode 100644 src/main/java/com/umc/naoman/domain/photo/elasticsearch/document/FaceVector.java create mode 100644 src/main/java/com/umc/naoman/domain/photo/elasticsearch/document/PhotoEs.java create mode 100644 src/main/java/com/umc/naoman/domain/photo/elasticsearch/document/SamplePhotoVector.java create mode 100644 src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/FaceVectorRepository.java create mode 100644 src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsRepository.java create mode 100644 src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/SamplePhotoVectorRepository.java diff --git a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/document/FaceVector.java b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/document/FaceVector.java new file mode 100644 index 0000000..a5f8adb --- /dev/null +++ b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/document/FaceVector.java @@ -0,0 +1,30 @@ +package com.umc.naoman.domain.photo.elasticsearch.document; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.elasticsearch.annotations.Document; +import org.springframework.data.elasticsearch.annotations.Field; +import org.springframework.data.elasticsearch.annotations.FieldType; + +import java.util.List; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Document(indexName = "face_vectors") +public class FaceVector { + @Id + private String id; + @Field(type = FieldType.Long) + private String shareGroupId; + @Field(type = FieldType.Keyword) + private String keyValue; + @Field(type = FieldType.Date) + private String date; + @Field(type = FieldType.Dense_Vector) + private List faceVector; +} diff --git a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/document/PhotoEs.java b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/document/PhotoEs.java new file mode 100644 index 0000000..4677011 --- /dev/null +++ b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/document/PhotoEs.java @@ -0,0 +1,32 @@ +package com.umc.naoman.domain.photo.elasticsearch.document; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.elasticsearch.annotations.Document; +import org.springframework.data.elasticsearch.annotations.Field; +import org.springframework.data.elasticsearch.annotations.FieldType; + +import java.util.List; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Document(indexName = "photos_es") +public class PhotoEs { + @Id + private String id; + @Field(type = FieldType.Long) + private String shareGroupId; + @Field(type = FieldType.Keyword) + private String keyValue; + @Field(type = FieldType.Date) + private String date; + @Field(type = FieldType.Long) + private List faceTag; + @Field(type = FieldType.Long) + private List downloadTag; +} diff --git a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/document/SamplePhotoVector.java b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/document/SamplePhotoVector.java new file mode 100644 index 0000000..da72324 --- /dev/null +++ b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/document/SamplePhotoVector.java @@ -0,0 +1,26 @@ +package com.umc.naoman.domain.photo.elasticsearch.document; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.elasticsearch.annotations.Document; +import org.springframework.data.elasticsearch.annotations.Field; +import org.springframework.data.elasticsearch.annotations.FieldType; + +import java.util.List; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Document(indexName = "sample_photo_vectors") +public class SamplePhotoVector { + @Id + private String id; + @Field(type = FieldType.Long) + private Long memberId; + @Field(type = FieldType.Dense_Vector) + private List faceVector; +} diff --git a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/FaceVectorRepository.java b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/FaceVectorRepository.java new file mode 100644 index 0000000..e0a52c7 --- /dev/null +++ b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/FaceVectorRepository.java @@ -0,0 +1,9 @@ +package com.umc.naoman.domain.photo.elasticsearch.repository; + +import com.umc.naoman.domain.photo.elasticsearch.document.FaceVector; +import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface FaceVectorRepository extends ElasticsearchRepository { +} diff --git a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsRepository.java b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsRepository.java new file mode 100644 index 0000000..e081d3b --- /dev/null +++ b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsRepository.java @@ -0,0 +1,9 @@ +package com.umc.naoman.domain.photo.elasticsearch.repository; + +import com.umc.naoman.domain.photo.elasticsearch.document.PhotoEs; +import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface PhotoEsRepository extends ElasticsearchRepository { +} diff --git a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/SamplePhotoVectorRepository.java b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/SamplePhotoVectorRepository.java new file mode 100644 index 0000000..9c30f67 --- /dev/null +++ b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/SamplePhotoVectorRepository.java @@ -0,0 +1,9 @@ +package com.umc.naoman.domain.photo.elasticsearch.repository; + +import com.umc.naoman.domain.photo.elasticsearch.document.SamplePhotoVector; +import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface SamplePhotoVectorRepository extends ElasticsearchRepository { +} From 8722dc90f6890db8f0654f66b098c29409669ed0 Mon Sep 17 00:00:00 2001 From: redblackblossom Date: Wed, 31 Jul 2024 19:55:43 +0900 Subject: [PATCH 04/18] =?UTF-8?q?feat=20:jackson=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.gradle b/build.gradle index 34e74bc..46fce07 100644 --- a/build.gradle +++ b/build.gradle @@ -65,6 +65,8 @@ dependencies { //elasticsearch implementation 'org.springframework.data:spring-data-elasticsearch:' implementation 'co.elastic.clients:elasticsearch-java:' + //elasticsearch 직렬화 및 역직렬화 + implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.0' } tasks.named('test') { From 8bb066af7312ee61dcd3421f01f359d16d71b7c2 Mon Sep 17 00:00:00 2001 From: redblackblossom Date: Fri, 2 Aug 2024 21:59:19 +0900 Subject: [PATCH 05/18] =?UTF-8?q?refact=20:=20=EC=97=98=EB=9D=BC=EC=8A=A4?= =?UTF-8?q?=ED=8B=B1=20=EC=84=9C=EC=B9=98=20=EB=A7=A4=ED=95=91=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD.=20=EB=8B=A4=EC=9D=B4=EB=82=98=EB=AF=B9=20=EB=A7=A4?= =?UTF-8?q?=ED=95=91=20=EA=B8=88=EC=A7=80.=20=EC=8B=9C=EA=B0=84=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=20YYYY-MM-DD=20HH:MM:SS=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/photo/elasticsearch/index/face_vectors.json | 3 ++- .../domain/photo/elasticsearch/index/photos_es.json | 9 +++++++-- .../photo/elasticsearch/index/sample_photo_vectors.json | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/face_vectors.json b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/face_vectors.json index cfd7672..b36b48d 100644 --- a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/face_vectors.json +++ b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/face_vectors.json @@ -6,6 +6,7 @@ } }, "mappings" : { + "dynamic": "false", "_routing": { "required" : true }, @@ -18,7 +19,7 @@ }, "createdAt" : { "type" : "date", - "format" : "basic_ordinal_date_time_no_millis" + "format": "yyyy-MM-dd HH:mm:ss" }, "faceVector" : { "type": "dense_vector", diff --git a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/photos_es.json b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/photos_es.json index b961c6b..c1525e9 100644 --- a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/photos_es.json +++ b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/photos_es.json @@ -1,3 +1,4 @@ + { "settings" : { "index" :{ @@ -6,6 +7,7 @@ } }, "mappings" : { + "dynamic": "false", "_routing": { "required" : true }, @@ -13,12 +15,15 @@ "shareGroupId" : { "type" : "long" }, - "keyValue" : { + "url" : { + "type" : "keyword" + }, + "name" : { "type" : "keyword" }, "createdAt" : { "type" : "date", - "format" : "basic_ordinal_date_time_no_millis" + "format": "yyyy-MM-dd HH:mm:ss" }, "faceTag" : { "type" : "long" diff --git a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/sample_photo_vectors.json b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/sample_photo_vectors.json index 5a7dcdc..ceb7f51 100644 --- a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/sample_photo_vectors.json +++ b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/index/sample_photo_vectors.json @@ -6,6 +6,7 @@ } }, "mappings" : { + "dynamic": "false", "properties" : { "memberId" : { "type" : "long" From 5039a2c66b7e6f9a175c905e7a093d213120c354 Mon Sep 17 00:00:00 2001 From: redblackblossom Date: Fri, 2 Aug 2024 22:03:11 +0900 Subject: [PATCH 06/18] =?UTF-8?q?refact=20:=20=EC=8A=A4=ED=94=84=EB=A7=81?= =?UTF-8?q?=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=97=98=EB=A6=AC=EC=8A=A4?= =?UTF-8?q?=ED=8B=B1=EC=84=9C=EC=B9=98=EA=B0=80=20=EC=97=98=EB=9D=BC?= =?UTF-8?q?=EC=8A=A4=ED=8B=B1=EC=84=9C=EC=B9=98=20=ED=81=B4=EB=9D=BC?= =?UTF-8?q?=EC=9D=B4=EC=96=B8=ED=8A=B8=EC=99=80=20=EC=A7=81=EB=A0=AC?= =?UTF-8?q?=ED=99=94=20=ED=94=84=EB=A0=88=EC=9E=84=EC=9B=8C=ED=81=AC?= =?UTF-8?q?=EC=97=90=20=EC=9D=98=EC=A1=B4=ED=95=98=EB=AF=80=EB=A1=9C=20?= =?UTF-8?q?=EB=91=90=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 46fce07..d3b1e02 100644 --- a/build.gradle +++ b/build.gradle @@ -64,9 +64,9 @@ dependencies { //elasticsearch implementation 'org.springframework.data:spring-data-elasticsearch:' - implementation 'co.elastic.clients:elasticsearch-java:' + //implementation 'co.elastic.clients:elasticsearch-java:' //elasticsearch 직렬화 및 역직렬화 - implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.0' + //implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.0' } tasks.named('test') { From 4d5b25f4f22aa751e24c32e858f506aac7459c4d Mon Sep 17 00:00:00 2001 From: redblackblossom Date: Fri, 2 Aug 2024 22:03:44 +0900 Subject: [PATCH 07/18] =?UTF-8?q?refact=20:=20=EC=8A=A4=ED=94=84=EB=A7=81?= =?UTF-8?q?=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=97=98=EB=A6=AC=EC=8A=A4?= =?UTF-8?q?=ED=8B=B1=EC=84=9C=EC=B9=98=EA=B0=80=20=EC=97=98=EB=9D=BC?= =?UTF-8?q?=EC=8A=A4=ED=8B=B1=EC=84=9C=EC=B9=98=20=ED=81=B4=EB=9D=BC?= =?UTF-8?q?=EC=9D=B4=EC=96=B8=ED=8A=B8=EC=99=80=20=EC=A7=81=EB=A0=AC?= =?UTF-8?q?=ED=99=94=20=ED=94=84=EB=A0=88=EC=9E=84=EC=9B=8C=ED=81=AC?= =?UTF-8?q?=EC=97=90=20=EC=9D=98=EC=A1=B4=ED=95=98=EB=AF=80=EB=A1=9C=20?= =?UTF-8?q?=EB=91=90=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 --- 1 file changed, 3 deletions(-) diff --git a/build.gradle b/build.gradle index d3b1e02..32922ea 100644 --- a/build.gradle +++ b/build.gradle @@ -64,9 +64,6 @@ dependencies { //elasticsearch implementation 'org.springframework.data:spring-data-elasticsearch:' - //implementation 'co.elastic.clients:elasticsearch-java:' - //elasticsearch 직렬화 및 역직렬화 - //implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.0' } tasks.named('test') { From 30f25edc61a23f4ce621afec1e73833746738874 Mon Sep 17 00:00:00 2001 From: redblackblossom Date: Fri, 2 Aug 2024 22:04:52 +0900 Subject: [PATCH 08/18] =?UTF-8?q?fefact=20:=20photos=5Fes=20=EB=8F=84?= =?UTF-8?q?=ED=81=90=EB=A8=BC=ED=8A=B8=20=20=ED=81=B4=EB=9E=98=EC=8A=A4?= =?UTF-8?q?=EC=97=90=20url=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../photo/elasticsearch/document/PhotoEs.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/document/PhotoEs.java b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/document/PhotoEs.java index 4677011..e4a6478 100644 --- a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/document/PhotoEs.java +++ b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/document/PhotoEs.java @@ -1,14 +1,12 @@ package com.umc.naoman.domain.photo.elasticsearch.document; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import org.springframework.data.annotation.Id; import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.annotations.Field; import org.springframework.data.elasticsearch.annotations.FieldType; +import java.time.LocalDateTime; import java.util.List; @Getter @@ -20,11 +18,13 @@ public class PhotoEs { @Id private String id; @Field(type = FieldType.Long) - private String shareGroupId; + private Long shareGroupId; @Field(type = FieldType.Keyword) - private String keyValue; + private String url; + @Field(type = FieldType.Keyword) + private String name; @Field(type = FieldType.Date) - private String date; + private String createdAt; @Field(type = FieldType.Long) private List faceTag; @Field(type = FieldType.Long) From f3b03a07d452f45df9440739c70ce4467534098f Mon Sep 17 00:00:00 2001 From: redblackblossom Date: Fri, 2 Aug 2024 22:08:29 +0900 Subject: [PATCH 09/18] =?UTF-8?q?refact=20:=20=EC=97=98=EB=9D=BC=EC=8A=A4?= =?UTF-8?q?=ED=8B=B1=EC=84=9C=EC=B9=98=20=EB=B0=B0=ED=8F=AC=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B8=ED=95=9C=20DB=20=EC=A3=BC=EC=86=8C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/umc/naoman/global/config/ElasticsearchConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/umc/naoman/global/config/ElasticsearchConfig.java b/src/main/java/com/umc/naoman/global/config/ElasticsearchConfig.java index 3150053..c1ad2ae 100644 --- a/src/main/java/com/umc/naoman/global/config/ElasticsearchConfig.java +++ b/src/main/java/com/umc/naoman/global/config/ElasticsearchConfig.java @@ -9,7 +9,7 @@ public class ElasticsearchConfig extends ElasticsearchConfiguration { @Override public ClientConfiguration clientConfiguration() { return ClientConfiguration.builder() - .connectedTo("localhost:9200") + .connectedTo("43.201.97.163:9200") .build(); } } From 9f50933a9661efe5bb10e1c0890f0ef5abe90a07 Mon Sep 17 00:00:00 2001 From: redblackblossom Date: Fri, 2 Aug 2024 22:11:56 +0900 Subject: [PATCH 10/18] =?UTF-8?q?feat=20:=20=EC=97=98=EB=9D=BC=EC=8A=A4?= =?UTF-8?q?=ED=8B=B1=EC=84=9C=EC=B9=98=20=ED=81=B4=EB=9D=BC=EC=9D=B4?= =?UTF-8?q?=EC=96=B8=20=ED=8A=B8=EB=8A=94=20IOException=EC=9D=84=20?= =?UTF-8?q?=EB=B0=9C=EC=83=9D=EC=8B=9C=ED=82=A4=EB=AF=80=EB=A1=9C,=20?= =?UTF-8?q?=ED=95=B4=EB=8B=B9=20=EC=98=88=EC=99=B8=EB=A5=BC=20=EB=9F=B0?= =?UTF-8?q?=ED=83=80=EC=9E=84=20=EC=98=88=EC=99=B8=EB=A1=9C=20=EC=B9=98?= =?UTF-8?q?=ED=99=98=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../error/ElasticsearchIOException.java | 27 +++++++++++++++++++ .../error/code/ElasticsearchErrorCode.java | 16 +++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/main/java/com/umc/naoman/global/error/ElasticsearchIOException.java create mode 100644 src/main/java/com/umc/naoman/global/error/code/ElasticsearchErrorCode.java diff --git a/src/main/java/com/umc/naoman/global/error/ElasticsearchIOException.java b/src/main/java/com/umc/naoman/global/error/ElasticsearchIOException.java new file mode 100644 index 0000000..3bd73da --- /dev/null +++ b/src/main/java/com/umc/naoman/global/error/ElasticsearchIOException.java @@ -0,0 +1,27 @@ +package com.umc.naoman.global.error; + +import lombok.Builder; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@Builder +@RequiredArgsConstructor +public class ElasticsearchIOException extends RuntimeException { + private final ErrorCode errorCode; + + public ElasticsearchIOException(String message, ErrorCode errorCode){ + super(message); + this.errorCode = errorCode; + } + + public ElasticsearchIOException(Throwable cause, ErrorCode errorCode){ + super(cause); + this.errorCode = errorCode; + } + + public ElasticsearchIOException(String message, Throwable cause, ErrorCode errorCode){ + super(message, cause); + this.errorCode = errorCode; + } +} diff --git a/src/main/java/com/umc/naoman/global/error/code/ElasticsearchErrorCode.java b/src/main/java/com/umc/naoman/global/error/code/ElasticsearchErrorCode.java new file mode 100644 index 0000000..a87e494 --- /dev/null +++ b/src/main/java/com/umc/naoman/global/error/code/ElasticsearchErrorCode.java @@ -0,0 +1,16 @@ +package com.umc.naoman.global.error.code; + +import com.umc.naoman.global.error.ErrorCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum ElasticsearchErrorCode implements ErrorCode { + ELASTICSEARCH_IOEXCEPTION(500, "EE000", "Elasticsearch IOException 발생") + ; + private final int status; + private final String code; + private final String message; + +} From a9e6ce51cf0a93083432595c80b7d8ab8af6f0c0 Mon Sep 17 00:00:00 2001 From: redblackblossom Date: Sat, 3 Aug 2024 20:08:06 +0900 Subject: [PATCH 11/18] =?UTF-8?q?feat=20:=20=EC=97=98=EB=9D=BC=EC=8A=A4?= =?UTF-8?q?=ED=8B=B1=EC=84=9C=EC=B9=98=20=EC=82=AC=EC=A7=84=20=EA=B2=80?= =?UTF-8?q?=EC=83=89=20Repository=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/PhotoEsClientRepository.java | 170 ++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepository.java diff --git a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepository.java b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepository.java new file mode 100644 index 0000000..4792ab8 --- /dev/null +++ b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepository.java @@ -0,0 +1,170 @@ +package com.umc.naoman.domain.photo.elasticsearch.repository; + +import co.elastic.clients.elasticsearch.ElasticsearchClient; +import co.elastic.clients.elasticsearch.core.BulkRequest; +import co.elastic.clients.elasticsearch.core.BulkResponse; +import co.elastic.clients.elasticsearch.core.SearchResponse; +import co.elastic.clients.elasticsearch.core.search.Hit; +import com.umc.naoman.domain.photo.elasticsearch.document.PhotoEs; +import com.umc.naoman.global.error.ElasticsearchIOException; +import com.umc.naoman.global.error.code.ElasticsearchErrorCode; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Repository; + +import java.io.IOException; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.List; + +@Repository +@RequiredArgsConstructor +public class PhotoEsClientRepository { + private final ElasticsearchClient elasticsearchClient; + + public void savePhotoBulk(List url, List nameList, Long shareGroupId) { + List photoEsList = new ArrayList<>(); + for(int i=0; iop + .index(idx -> idx + .index("photos_es") + .routing(shareGroupId.toString()) + .document(photoEs) + ) + ); + } + try { + BulkResponse result = elasticsearchClient.bulk(bulkBuilder.build()); + } catch (IOException e) { + throw new ElasticsearchIOException(e, ElasticsearchErrorCode.ELASTICSEARCH_IOEXCEPTION); + } + } + + public Page findPhotoEsByShareGroupId(Long shareGroupId, Pageable pageable) { + SearchResponse response = null; + + pageable.getPageNumber(); + try{ + response = elasticsearchClient.search(s->s + .index("photos_es") + .routing(shareGroupId.toString()) + .from(getFrom(pageable)) + .size(pageable.getPageSize()) + .sort(sort -> sort + .field(f -> f + .field("createdAt"))) + .query(q->q + .term(t->t + .field("shareGroupId") + .value(shareGroupId) + ) + ), + PhotoEs.class + ); + } catch (IOException e) { + throw new ElasticsearchIOException(e, ElasticsearchErrorCode.ELASTICSEARCH_IOEXCEPTION); + } + return toPagePhotoEs(response.hits().hits(), pageable); + } + + public Page findPhotoEsByShareGroupIdAndFaceTag(Long shareGroupId,Long faceTag, Pageable pageable) throws IOException{ + SearchResponse response = null; + try{ + response = elasticsearchClient.search(s->s + .index("photos_es") + .routing(shareGroupId.toString()) + .from(getFrom(pageable)) + .size(pageable.getPageSize()) + .sort(sort -> sort + .field(f -> f + .field("createdAt"))) + .query(q->q + .bool(b->b + .must(m->m + .term(t->t + .field("shareGroupId") + .value(shareGroupId) + ) + ) + .must(m->m + .term(t->t + .field("faceTag") + .value(faceTag) + ) + ) + ) + ), + PhotoEs.class + ); + } catch (IOException e) { + throw new ElasticsearchIOException(e, ElasticsearchErrorCode.ELASTICSEARCH_IOEXCEPTION); + } + + return toPagePhotoEs(response.hits().hits(), pageable); + } + + public Page findPhotoEsByShareGroupIdAndNotFaceTag(Long shareGroupId, Pageable pageable){ + SearchResponse response = null; + try{ + response = elasticsearchClient.search(s->s + .index("photos_es") + .routing(shareGroupId.toString()) + .from(getFrom(pageable)) + .size(pageable.getPageSize()) + .sort(sort -> sort + .field(f -> f + .field("createdAt"))) + .query(q->q + .bool(b -> b + .must(m -> m + .term(t -> t + .field("shareGroupId") + .value(shareGroupId) + ) + ) + .mustNot(mn -> mn + .exists(e -> e + .field("faceTag") + ) + ) + ) + ), + PhotoEs.class + ); + }catch (IOException e){ + throw new ElasticsearchIOException(e, ElasticsearchErrorCode.ELASTICSEARCH_IOEXCEPTION); + } + + return toPagePhotoEs(response.hits().hits(), pageable); + } + + String esTimeFormat(LocalDateTime localDateTime){ + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + return localDateTime.format(dateTimeFormatter); + } + + private Page toPagePhotoEs(List> hits, Pageable pageable){ + List photoEsList = new ArrayList<>(); + hits.forEach(hit->{ + photoEsList.add(hit.source()); + }); + return new PageImpl<>(photoEsList, pageable, hits.size()); + } + + private int getFrom(Pageable pageable){ + return pageable.getPageNumber() * pageable.getPageSize(); + } +} From 66ec57cd2d0414153fc12fbee419cd5dadef1758 Mon Sep 17 00:00:00 2001 From: redblackblossom Date: Sat, 3 Aug 2024 20:09:14 +0900 Subject: [PATCH 12/18] =?UTF-8?q?feat=20:=20elsticsearch=20service=20?= =?UTF-8?q?=ED=8B=80=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../photo/elasticsearch/service/PhotoEsService.java | 4 ++++ .../elasticsearch/service/PhotoEsServiceImpl.java | 13 +++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 src/main/java/com/umc/naoman/domain/photo/elasticsearch/service/PhotoEsService.java create mode 100644 src/main/java/com/umc/naoman/domain/photo/elasticsearch/service/PhotoEsServiceImpl.java diff --git a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/service/PhotoEsService.java b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/service/PhotoEsService.java new file mode 100644 index 0000000..0e52701 --- /dev/null +++ b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/service/PhotoEsService.java @@ -0,0 +1,4 @@ +package com.umc.naoman.domain.photo.elasticsearch.service; + +public interface PhotoEsService { +} diff --git a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/service/PhotoEsServiceImpl.java b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/service/PhotoEsServiceImpl.java new file mode 100644 index 0000000..1b46506 --- /dev/null +++ b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/service/PhotoEsServiceImpl.java @@ -0,0 +1,13 @@ +package com.umc.naoman.domain.photo.elasticsearch.service; + +import com.umc.naoman.domain.photo.elasticsearch.repository.FaceVectorRepository; +import com.umc.naoman.domain.photo.elasticsearch.repository.PhotoEsRepository; +import com.umc.naoman.domain.photo.service.PhotoService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class PhotoEsServiceImpl implements PhotoEsService { + +} From 9e87472e1f74377b554ab04e49b50c6d0f8c7fe3 Mon Sep 17 00:00:00 2001 From: redblackblossom Date: Sun, 4 Aug 2024 19:54:56 +0900 Subject: [PATCH 13/18] =?UTF-8?q?refact=20:=20=EC=97=98=EB=9D=BC=EC=8A=A4?= =?UTF-8?q?=ED=8B=B1=EC=84=9C=EC=B9=98=20url=20Value=20=EC=97=90=EB=85=B8?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EC=85=98=EC=9C=BC=EB=A1=9C=20=EC=A3=BC?= =?UTF-8?q?=EC=9E=85=EB=B0=9B=EB=8F=84=EB=A1=9D=20=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/umc/naoman/global/config/ElasticsearchConfig.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/umc/naoman/global/config/ElasticsearchConfig.java b/src/main/java/com/umc/naoman/global/config/ElasticsearchConfig.java index c1ad2ae..2382cb6 100644 --- a/src/main/java/com/umc/naoman/global/config/ElasticsearchConfig.java +++ b/src/main/java/com/umc/naoman/global/config/ElasticsearchConfig.java @@ -1,15 +1,19 @@ package com.umc.naoman.global.config; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.data.elasticsearch.client.ClientConfiguration; import org.springframework.data.elasticsearch.client.elc.ElasticsearchConfiguration; @Configuration public class ElasticsearchConfig extends ElasticsearchConfiguration { + @Value("${spring.elasticsearch.host}") + private String elasticsearchHost; + @Override public ClientConfiguration clientConfiguration() { return ClientConfiguration.builder() - .connectedTo("43.201.97.163:9200") + .connectedTo(elasticsearchHost) .build(); } } From 923c4a69d21037d901a3b84c25985d27ad40f412 Mon Sep 17 00:00:00 2001 From: redblackblossom Date: Sun, 4 Aug 2024 20:12:39 +0900 Subject: [PATCH 14/18] =?UTF-8?q?BusinessException=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=9E=90=EC=97=90=20Throwable,ErrorCode=EB=A5=BC=20=EB=B0=9B?= =?UTF-8?q?=EB=8A=94=20=20=EC=83=9D=EC=84=B1=EC=9E=90=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/umc/naoman/global/error/BusinessException.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/umc/naoman/global/error/BusinessException.java b/src/main/java/com/umc/naoman/global/error/BusinessException.java index 45fd93a..2ac3bdc 100644 --- a/src/main/java/com/umc/naoman/global/error/BusinessException.java +++ b/src/main/java/com/umc/naoman/global/error/BusinessException.java @@ -9,4 +9,9 @@ @RequiredArgsConstructor public class BusinessException extends RuntimeException { private final ErrorCode errorCode; + + public BusinessException(ErrorCode errorCode, Throwable cause) { + super(errorCode.getMessage(), cause); + this.errorCode = errorCode; + } } \ No newline at end of file From ceb0a62af727bdd86ef703c3bac77bcc817b4043 Mon Sep 17 00:00:00 2001 From: redblackblossom Date: Sun, 4 Aug 2024 20:16:31 +0900 Subject: [PATCH 15/18] =?UTF-8?q?refact=20:=EC=97=98=EB=9D=BC=EC=8A=A4?= =?UTF-8?q?=ED=8B=B1=EC=84=9C=EC=B9=98=20=ED=81=B4=EB=9D=BC=EC=9D=B4?= =?UTF-8?q?=EC=96=B8=ED=8A=B8=EC=9D=98=20crud=EA=B0=80=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D=EC=8B=9C=ED=82=A4=EB=8A=94=20IOException=EC=9D=84=20B?= =?UTF-8?q?ussinessEception=EC=9C=BC=EB=A1=9C=20=EB=B0=94=EA=BF=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/PhotoEsClientRepository.java | 10 +++---- .../error/ElasticsearchIOException.java | 27 ------------------- 2 files changed, 5 insertions(+), 32 deletions(-) delete mode 100644 src/main/java/com/umc/naoman/global/error/ElasticsearchIOException.java diff --git a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepository.java b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepository.java index 4792ab8..2dcf340 100644 --- a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepository.java +++ b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepository.java @@ -6,7 +6,7 @@ import co.elastic.clients.elasticsearch.core.SearchResponse; import co.elastic.clients.elasticsearch.core.search.Hit; import com.umc.naoman.domain.photo.elasticsearch.document.PhotoEs; -import com.umc.naoman.global.error.ElasticsearchIOException; +import com.umc.naoman.global.error.BusinessException; import com.umc.naoman.global.error.code.ElasticsearchErrorCode; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; @@ -49,7 +49,7 @@ public void savePhotoBulk(List url, List nameList, Long shareGro try { BulkResponse result = elasticsearchClient.bulk(bulkBuilder.build()); } catch (IOException e) { - throw new ElasticsearchIOException(e, ElasticsearchErrorCode.ELASTICSEARCH_IOEXCEPTION); + throw new BusinessException(ElasticsearchErrorCode.ELASTICSEARCH_IOEXCEPTION, e); } } @@ -75,7 +75,7 @@ public Page findPhotoEsByShareGroupId(Long shareGroupId, Pageable pagea PhotoEs.class ); } catch (IOException e) { - throw new ElasticsearchIOException(e, ElasticsearchErrorCode.ELASTICSEARCH_IOEXCEPTION); + throw new BusinessException(ElasticsearchErrorCode.ELASTICSEARCH_IOEXCEPTION, e); } return toPagePhotoEs(response.hits().hits(), pageable); } @@ -110,7 +110,7 @@ public Page findPhotoEsByShareGroupIdAndFaceTag(Long shareGroupId,Long PhotoEs.class ); } catch (IOException e) { - throw new ElasticsearchIOException(e, ElasticsearchErrorCode.ELASTICSEARCH_IOEXCEPTION); + throw new BusinessException(ElasticsearchErrorCode.ELASTICSEARCH_IOEXCEPTION, e); } return toPagePhotoEs(response.hits().hits(), pageable); @@ -145,7 +145,7 @@ public Page findPhotoEsByShareGroupIdAndNotFaceTag(Long shareGroupId, P PhotoEs.class ); }catch (IOException e){ - throw new ElasticsearchIOException(e, ElasticsearchErrorCode.ELASTICSEARCH_IOEXCEPTION); + throw new BusinessException(ElasticsearchErrorCode.ELASTICSEARCH_IOEXCEPTION, e); } return toPagePhotoEs(response.hits().hits(), pageable); diff --git a/src/main/java/com/umc/naoman/global/error/ElasticsearchIOException.java b/src/main/java/com/umc/naoman/global/error/ElasticsearchIOException.java deleted file mode 100644 index 3bd73da..0000000 --- a/src/main/java/com/umc/naoman/global/error/ElasticsearchIOException.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.umc.naoman.global.error; - -import lombok.Builder; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@Builder -@RequiredArgsConstructor -public class ElasticsearchIOException extends RuntimeException { - private final ErrorCode errorCode; - - public ElasticsearchIOException(String message, ErrorCode errorCode){ - super(message); - this.errorCode = errorCode; - } - - public ElasticsearchIOException(Throwable cause, ErrorCode errorCode){ - super(cause); - this.errorCode = errorCode; - } - - public ElasticsearchIOException(String message, Throwable cause, ErrorCode errorCode){ - super(message, cause); - this.errorCode = errorCode; - } -} From 72e76ce5dde586b50a246246c38a2ac23edae10e Mon Sep 17 00:00:00 2001 From: redblackblossom Date: Sun, 4 Aug 2024 20:27:15 +0900 Subject: [PATCH 16/18] =?UTF-8?q?refact=20:=20=EB=8F=84=EB=AE=A4=EB=A8=BC?= =?UTF-8?q?=ED=8A=B8=EB=AA=85=20smaple=5Fphoto=5Fvectors=EC=97=90=EC=84=9C?= =?UTF-8?q?=20sample=5Fface=5Fvectors=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{SamplePhotoVector.java => SampleFaceVector.java} | 4 ++-- ...oVectorRepository.java => SampleFaceVectorRepository.java} | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename src/main/java/com/umc/naoman/domain/photo/elasticsearch/document/{SamplePhotoVector.java => SampleFaceVector.java} (89%) rename src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/{SamplePhotoVectorRepository.java => SampleFaceVectorRepository.java} (69%) diff --git a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/document/SamplePhotoVector.java b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/document/SampleFaceVector.java similarity index 89% rename from src/main/java/com/umc/naoman/domain/photo/elasticsearch/document/SamplePhotoVector.java rename to src/main/java/com/umc/naoman/domain/photo/elasticsearch/document/SampleFaceVector.java index da72324..51b35ca 100644 --- a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/document/SamplePhotoVector.java +++ b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/document/SampleFaceVector.java @@ -15,8 +15,8 @@ @Builder @NoArgsConstructor @AllArgsConstructor -@Document(indexName = "sample_photo_vectors") -public class SamplePhotoVector { +@Document(indexName = "sample_face_vectors") +public class SampleFaceVector { @Id private String id; @Field(type = FieldType.Long) diff --git a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/SamplePhotoVectorRepository.java b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/SampleFaceVectorRepository.java similarity index 69% rename from src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/SamplePhotoVectorRepository.java rename to src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/SampleFaceVectorRepository.java index 9c30f67..98a866d 100644 --- a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/SamplePhotoVectorRepository.java +++ b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/SampleFaceVectorRepository.java @@ -1,9 +1,9 @@ package com.umc.naoman.domain.photo.elasticsearch.repository; -import com.umc.naoman.domain.photo.elasticsearch.document.SamplePhotoVector; +import com.umc.naoman.domain.photo.elasticsearch.document.SampleFaceVector; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; import org.springframework.stereotype.Repository; @Repository -public interface SamplePhotoVectorRepository extends ElasticsearchRepository { +public interface SampleFaceVectorRepository extends ElasticsearchRepository { } From 53c2a1c6d985b33d579f5520d5fcf6c15b9b1058 Mon Sep 17 00:00:00 2001 From: redblackblossom Date: Sun, 4 Aug 2024 20:35:07 +0900 Subject: [PATCH 17/18] =?UTF-8?q?refact=20:=20toPagePhotoEs=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20=EB=B0=A9=EC=8B=9D=20=EB=B0=98=EB=B3=B5=EB=AC=B8?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=8A=A4=ED=8A=B8=EB=A6=BC=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../elasticsearch/repository/PhotoEsClientRepository.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepository.java b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepository.java index 2dcf340..93edaac 100644 --- a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepository.java +++ b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepository.java @@ -19,6 +19,7 @@ import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; @Repository @RequiredArgsConstructor @@ -157,10 +158,7 @@ String esTimeFormat(LocalDateTime localDateTime){ } private Page toPagePhotoEs(List> hits, Pageable pageable){ - List photoEsList = new ArrayList<>(); - hits.forEach(hit->{ - photoEsList.add(hit.source()); - }); + List photoEsList = hits.stream().map(Hit::source).collect(Collectors.toList()); return new PageImpl<>(photoEsList, pageable, hits.size()); } From 3cc2d502925f48e316172626a78d3b8387c760b4 Mon Sep 17 00:00:00 2001 From: redblackblossom Date: Sun, 4 Aug 2024 20:37:27 +0900 Subject: [PATCH 18/18] =?UTF-8?q?refact=20:=20PhotoEsClientRepository?= =?UTF-8?q?=EC=97=90=20=EA=B0=84=EB=8B=A8=ED=95=9C=20=EC=A3=BC=EC=84=9D=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../elasticsearch/repository/PhotoEsClientRepository.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepository.java b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepository.java index 93edaac..d78fa7d 100644 --- a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepository.java +++ b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepository.java @@ -26,6 +26,7 @@ public class PhotoEsClientRepository { private final ElasticsearchClient elasticsearchClient; + //사진 업로드 시 ES에 벌크로 업로드 public void savePhotoBulk(List url, List nameList, Long shareGroupId) { List photoEsList = new ArrayList<>(); for(int i=0; i url, List nameList, Long shareGro } } + //특정 공유 그룹의 모든 사진 검색 public Page findPhotoEsByShareGroupId(Long shareGroupId, Pageable pageable) { SearchResponse response = null; @@ -81,6 +83,7 @@ public Page findPhotoEsByShareGroupId(Long shareGroupId, Pageable pagea return toPagePhotoEs(response.hits().hits(), pageable); } + //특정 공유 그룹의 얼굴이 태그된 사진 검색 public Page findPhotoEsByShareGroupIdAndFaceTag(Long shareGroupId,Long faceTag, Pageable pageable) throws IOException{ SearchResponse response = null; try{ @@ -117,6 +120,7 @@ public Page findPhotoEsByShareGroupIdAndFaceTag(Long shareGroupId,Long return toPagePhotoEs(response.hits().hits(), pageable); } + //특정 공유 그룹의 얼굴이 태그되지 않은 사진 검색 public Page findPhotoEsByShareGroupIdAndNotFaceTag(Long shareGroupId, Pageable pageable){ SearchResponse response = null; try{