context 에 따른 bool 쿼리의 동작

LEE_DEV_LOG·2022년 2월 25일
0

elasticsearch 에는 query context와 filter context 2개로 나뉘어 동작한다.
must, should 는 query context 그리고 filter, must_not 은 filter context이다.

must와 should 는 socre를 계산하여야 하므로 query context에서 동작하고 filter와 must_not 은 score계산이 불필요 하므로 filter context 에서 동작하여 cache 의 득을 볼 수 있다.

bool쿼리에 should 만있는 경우 적어도 should의 조건이 하나라도 만족해야 값이 조회딘다.
하지만 filter or must와 함께 왔을 때는 should 조건이 하나 이상 match 되어야 한다.

constant score query의 filter으로 인해 bool query 전체가 filter context로 동작하기 때문이고, bool query의 should clause는 context에 따라 다르게 동작한다.
(query 절 하단에 constant_score 를 적용하면 이것은 filter context 에서 작동)

should 가 filter context 에서 적어도 반드시 하나의 조건을 만족해야 한다면 만일 그렇게 작동하기를 원하지 않는 경우 어떻게 해야할까?
아래 그림처럼 "minimum_should_match": 0 옵션을 주어 해결이 가능하다고 한다.

참조 사이트: https://unuseful.tistory.com/21

profile
LEE_DEV_LOG

0개의 댓글