ELASTIC SEARCH는 뭘로 만들어졌을까?

SOUTH DARIA·2022년 2월 18일
2

개념 박아넣기

목록 보기
2/3

오늘 es 관련 담소를 나누다가,
문득 궁금한 점이 생겼다.

es는 뭘로 개발되어있을까..?

궁금해진 사유는 이렇다.

1년 동안의 주문 데이터를 요일별로 조회해와야하는데, 
그럼 es 서버 터질 것 같으니 나눠서 하자.
평균을 내야하는데 연산이 들어가니까, 
es 서버가 aggregation하면서 메모리를 너무 많이 먹으니 서버 증설 해야하지 않을까..??

뭐 대충 이런 얘기를 하다가,,

es는 연산을 어떻게 하지...?
무엇을 기반으로 하지..?

뭐 이렇게...

궁금증 해소 시작

토독토독 구그루에 엘라스틱서치를 검색해봤다 !

hey.. hello 일래스틱서치..

엘라스틱서치란?

엘라스틱서치란 루씬 기반의 검색 엔진이다.
elasticsearch는 자바로 개발되어 있으며 아파치 라이선스 조항에 의거하여 오픈 소스로 출시되어 있다.

루씬이란?

자바 언어로 이루어진 정보 검색 라이브러리 자유-오픈 소스 소프트웨어이다.
아파치 라이선스 하에 배포된다..

오픈 소스.. 이건 못 참지

오픈 소스.. 이건 못 참는다.

야너두클릭해

자연스럽게 포크해준다....

클론 받는데 용량이 대단하다..
내 똥컴 죽겠다..

맨날 쓰는 RestHighLevelClient 코드를 뜯어보자..

코드 살펴보기

RestHighLevelClient의 생성자 위의 주석의 내용이다.

  • 요청을 수행하고
  • 플러그인을 통해 Elasticsearch에 추가된 사용자 지정 응답 섹션을 구문 분석할 수 있는 항목 목록입니다.
  • 이 생성자는 외부에서 생성된 저수준 REST 클라이언트를 제공해야 하는 경우 서브클래스에서 호출할 수 있습니다.
  • 소비자 인수를 사용하면 {@link #close()} 메서드가 호출될 때 수행해야 하는 작업을 제어할 수 있습니다.
  • 또한 서브클래스는 플러그인을 통해 Elasticsearch에 추가된 사용자 정의 응답 섹션에 대한 파서를 제공할 수 있습니다.

요건 해당 객체를 쓰면서 아는 사항이었으니 패쓰!!

내가 궁금한 건..
대체 이 아이는 베이스가 무엇인가..

public class RestHighLevelClient implements Closeable {

    private final RestClient client;
    private final NamedXContentRegistry registry;
    private final CheckedConsumer<RestClient, IOException> doClose;

    private final IndicesClient indicesClient = new IndicesClient(this);
    private final ClusterClient clusterClient = new ClusterClient(this);
    private final IngestClient ingestClient = new IngestClient(this);
    private final SnapshotClient snapshotClient = new SnapshotClient(this);
    private final TasksClient tasksClient = new TasksClient(this);
    private final XPackClient xPackClient = new XPackClient(this);
    private final WatcherClient watcherClient = new WatcherClient(this);
    private final GraphClient graphClient = new GraphClient(this);
    private final LicenseClient licenseClient = new LicenseClient(this);
    private final IndexLifecycleClient indexLifecycleClient = new IndexLifecycleClient(this);
    private final MigrationClient migrationClient = new MigrationClient(this);
    private final MachineLearningClient machineLearningClient = new MachineLearningClient(this);
    private final SecurityClient securityClient = new SecurityClient(this);
    private final RollupClient rollupClient = new RollupClient(this);
    private final CcrClient ccrClient = new CcrClient(this);
    
    ...더보기

Closeable.java


얘는 뭐하는 놈인가?

package java.io;

public interface Closeable extends AutoCloseable {
    void close() throws IOException;
}

close라는 이름을 가진 IOException 예외처리가 가능한 메소드이다.

이렇다면 RestHighLevelClient.java에서는 어떻게 사용되고 있을까?

@Override
    public final void close() throws IOException {
        doClose.accept(client);
    }

오.. 이런 메소드가 있었구나..?

나는 따로 아래와 같은 메소드로 구현했었다.

    public void closeClient(Closeable client) {
        try {
            Closeables.close(client, true);
        } catch (Exception e) {
            log.error("closeClientNLog", e);
        }
    }

다음에 es 환경을 구축할 때는 커스텀한 환경이 아닌 es 기본 그대로를 사용하는 코드도 구현해봐야겠다!

profile
고양이와 함께 - 끄적끄적 개발하고 이씁니다 ~!

0개의 댓글