-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from Na-o-man/feature/85/es_photo_delete
[FEAT] 엘라스틱서치 사진 삭제 로직 추가
- Loading branch information
Showing
4 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...java/com/umc/naoman/domain/photo/elasticsearch/repository/FaceVectorClientRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.umc.naoman.domain.photo.elasticsearch.repository; | ||
|
||
import co.elastic.clients.elasticsearch.ElasticsearchClient; | ||
import co.elastic.clients.elasticsearch._types.FieldValue; | ||
import com.umc.naoman.global.error.BusinessException; | ||
import com.umc.naoman.global.error.code.ElasticsearchErrorCode; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class FaceVectorClientRepository { | ||
private final ElasticsearchClient elasticsearchClient; | ||
|
||
//photoName으로 face_vectors 삭제 | ||
public void deleteFaceVectorsByPhotoName(List<String> photoNameList){ | ||
List<FieldValue> fieldValuePhotoNameList = photoNameList.stream() | ||
.map(FieldValue::of) | ||
.toList(); | ||
try { | ||
elasticsearchClient.deleteByQuery(delete -> delete | ||
.index("face_vectors") | ||
.query(q -> q | ||
.terms(t -> t | ||
.field("name") | ||
.terms(te -> te.value(fieldValuePhotoNameList)) | ||
) | ||
) | ||
); | ||
} catch (IOException e){ | ||
throw new BusinessException(ElasticsearchErrorCode.ELASTICSEARCH_IOEXCEPTION, e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...om/umc/naoman/domain/photo/elasticsearch/repository/SampleFaceVectorClientRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.umc.naoman.domain.photo.elasticsearch.repository; | ||
|
||
import co.elastic.clients.elasticsearch.ElasticsearchClient; | ||
import co.elastic.clients.elasticsearch._types.FieldValue; | ||
import com.umc.naoman.global.error.BusinessException; | ||
import com.umc.naoman.global.error.code.ElasticsearchErrorCode; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.io.IOException; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class SampleFaceVectorClientRepository { | ||
private final ElasticsearchClient elasticsearchClient; | ||
|
||
public void deleteSampleFaceVectorByMemberId(Long memberId) { | ||
try { | ||
elasticsearchClient.deleteByQuery(d -> d | ||
.index("sample_face_vectors") | ||
.query(q -> q | ||
.term(t -> t | ||
.field("memberId") | ||
.value(FieldValue.of(memberId)) | ||
) | ||
) | ||
); | ||
} catch (IOException e){ | ||
throw new BusinessException(ElasticsearchErrorCode.ELASTICSEARCH_IOEXCEPTION, e); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...ava/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsClientRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.umc.naoman.domain.photo.elasticsearch.repository; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@SpringBootTest | ||
class PhotoEsClientRepositoryTest { | ||
@Autowired | ||
private PhotoEsClientRepository photoEsClientRepository; | ||
@Test | ||
public void test() { | ||
List<Long> val = photoEsClientRepository.deletePhotoEsByFaceTag(1001L); | ||
|
||
} | ||
} |