프로필사진

Go, Vantage point

가까운 곳을 걷지 않고 서는 먼 곳을 갈 수 없다.


Github | https://github.com/overnew/

Blog | https://everenew.tistory.com/





티스토리 뷰

반응형

 

 

 

 

채용 공고를 빠르게 검색하는 용도로 Elastic Search를 사용하고 있는데,

채용 공고는 몇달이나 지난 것은 의미가 없기 때문에 날짜가 가까울수록 높은 Score를 낼 수 있도록 만들어야 한다. 

 

 

script_score를 사용하면 부분 텍스트나 숫자로 score를 만들기 때문에, Decay functions을 사용해야 한다.

 

 

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-decay

 

Function score query | Elasticsearch Guide [8.11] | Elastic

Keep in mind that taking the log() of 0, or the square root of a negative number is an illegal operation, and an exception will be thrown. Be sure to limit the values of the field with a range filter to avoid this, or use log1p and ln1p.

www.elastic.co

 

 

 

Decay functions을 사용하면 거리나 날짜 Field로 부터 score를 만들 수 있다.

해당 Field 값이 origin에서 offset을 초과하여 떨어져 있다면부터 특정 값인 decay를 적용시킬 수 있다.

(scale값은 offset x 2 인것 같다.)

 

 

아쉽게도 날짜의 차이만큼 score 점수로 환산하는 것은 없는 것 같기 때문에, 단계적으로 offset을 늘려가면서 적용해 보자.

 

 

 

 

"functions": [
                    {"gauss": {
                        "date_field": {
                            "origin": origin,	#origin == today
                            "scale": "6d",
                            "offset": "3d",
                            "decay": 0.8
                        }
                    }},
                    {"gauss": {
                        "date_field": {
                            "origin": origin,
                            "scale": "14d",
                            "offset": "7d",
                            "decay": 0.4
                        }
                    }},
                    {"gauss": {
                        "date_field": {
                            "origin": origin,
                            "scale": "28d",
                            "offset": "14d",
                            "decay": 0.1
                        }
                    }}
                ]

 

일단 최신 공고라고 할 수 있는 3일 이내의  공고에게는 score 1을 유지하고 그 이외의 공고에는 score를 0.8로 낮추었다.

7일이 넘은 공고는 최신 공고보다 검색에서 조금 덜 강조해 주어도 되기 때문에 0.4로 낮춘다.

2주일이 넘었다면 채용 공고의 신선도(?)가 떨어지기 때문에 0.1로 낮춘다.

 

물론 이런 식으로 만 적용한다면,  단순이 date_field를 날짜순으로 sort 해서 search 하면 되기 때문에 의미가 없다.

따라서 추가적인 score 계산을 넣어주어, decay값에 구해진 score를 곱한 최종 score를 만들어 주자.

 

 

 

 

 

 

 

 

 

function_score에 추가적으로 query, bool, should를 넣어서 특정 단어가 들어간 경우 score를 boost 하도록 만들어주었다.

만약 특정 조건이 반드시 만족되어야 한다면 filter에 조건을 넣어서 필더링도 할 수 있다.(score는 고려하지 x)

 

최종적으로는 "score_mode": "multiply"를 통해서 score를 decay값과 곱해준다.

해당 쿼리에서는 3일 이내의 정보 중에서 title에 특정 단어가 들어갈수록 높은 score가 나오게 된다.

 

 

 

반응형
댓글
반응형
인기글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함