Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

7-1 [BE] [메인 - 검색창 - 자동완성] Elasticsearch db 연결 #55

Merged
merged 20 commits into from
Nov 23, 2022

Conversation

JunYupK
Copy link
Collaborator

@JunYupK JunYupK commented Nov 22, 2022

개요

기존은 자동완성기능 api를 호출할때 crossref의 해당 keyword로 5개의 데이터를 요청하였습니다.
외부의 api에 의존하다보니 시간이 1s ~ 13로 평균적으로는 5s 로 자동완성기능이라기에는 많은 요청 시간과 변동이 심했습니다.
이제 이를 elasticsearch에 캐싱하여, 한번 호출한 연관검색어는 캐싱이 되도록 설정하였습니다. (현재는 그대로 캐싱)
캐싱을 하니 10~12ms로 매우 빠르게 성능 향상을 할 수 있었습니다.
이후에 캐싱작업을 대폭 확대하여 자동적으로 BE측에서 캐싱작업을 수행하도록 보완할 예정입니다.

작업사항

  • elasticsearch를 docker를 통하여 연결하였습니다.
  • elasticsearch에 데이터를 넣는 작업을 테스트 하였습니다.
  • elasticsearch에서 query를 통하여 원하는 데이터 값을 가져오는 작업을 수행하였습니다. (title, author) (해당 알고리즘은 계속하여 유지 보수 필요합니다.)
  • 자동완성기능 api를 호출할 때 elastic search에 해당 키워드의 데이터가 있으면 elastic search의 데이터를 response해주고, 없으면 corssref api를 호출하여, 해당 데이터를 elasticsearch에 집어넣고 response 파이프라인을 추가하였습니다.

Copy link
Member

@leesungbin leesungbin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

꽤나 대형 커밋이 되었네요 ㅎㅎ
ranking 테스트 부분과, elastic search 부분은 PR을 나눠도 좋겠습니다.

HttpModule,
ElasticsearchModule.registerAsync({
useFactory: () => ({
node: `http://localhost:9200`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은 env 로 대체되어야하겠네요.
아마 개발서버로 배포될 때 연결이 안될텐데, password 설정까지 고려하는게 좋을 것 같습니다.

})
export class SearchModule {}
// -e "xpack.security.enabled=false"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

password 설정한 후에는 docker 이미지에 해당 환경변수는 true로 하면 되겠습니다.
이 스택오버플로우 글을 참고하면 될 것 같습니다.

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

search controller 테스트는 /search/tests 안에 있어서, 이 파일은 지우면 좋겠습니다.

tmp.count = Number(score);
result.push(tmp);
}),
);
return result;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은 result에 push하지 않고, Promise.all 자체를 return 해줘도 될 것 같은데요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은 추후에 수정해보록하겠습니다. 이 PR은 elastic search에 관심을 두어야 할 것 같습니다.

password: process.env.REDIS_PASSWORD,
},
}),
],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redis module에 대한 mockup을 만들어서 진행해도 좋을 것 같아요~

Comment on lines +44 to +46
papers.forEach((paper) => {
this.putElasticSearch(paper);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

papers 배열을 elasticSearch에 한번에 넣어도 될 것 같습니다.

@leesungbin leesungbin merged commit 99c8923 into dev Nov 23, 2022
@JunYupK JunYupK deleted the feature/elastic-setting branch November 24, 2022 04:49
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants