Boosting 쿼리
Boosting 쿼리
boosting 쿼리는 positive 쿼리와 일치하는 문서를 반환하고, 그 중 negative 쿼리와도 일치하는 문서는 관련성을 낮춰요. 검색 결과에서 문서를 완전히 제외하지 않고 관련성만 낮추고 싶을 때 유용합니다.
출처: 문서
본문
단어 "pitcher"를 검색한다면 결과가 야구 선수나 액체를 담는 용기에 관련될 수 있어요. 야구 맥락의 검색이라면 must_not 절을 사용해 "glass"나 "water"가 포함된 결과를 완전히 제외하고 싶을 수도 있어요. 하지만 이런 결과를 유지하면서 관련성만 낮추고 싶다면 boosting 쿼리로 그렇게 할 수 있어요.
boosting 쿼리는 positive 쿼리와 일치하는 문서를 반환해요. 그 문서들 중 negative 쿼리와도 일치하는 것은 관련성이 더 낮게 점수화돼요(관련성 점수에 negative 부스트 요인이 곱해져요).
예시 (Example)
다음과 같이 인덱싱한 두 문서가 있는 인덱스를 생각해 볼게요.
PUT testindex/_doc/1
{
"article_name": "The greatest pitcher in baseball history"
}
PUT testindex/_doc/2
{
"article_name": "The making of a glass pitcher"
}
다음 match 쿼리를 사용해 단어 "pitcher"를 포함한 문서를 검색하세요.
GET testindex/_search
{
"query": {
"match": {
"article_name": "pitcher"
}
}
}
반환된 두 문서 모두 동일한 관련성 점수를 가져요.
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 2,
"relation": "eq"
},
"max_score": 0.18232156,
"hits": [
{
"_index": "testindex",
"_id": "1",
"_score": 0.18232156,
"_source": {
"article_name": "The greatest pitcher in baseball history"
}
},
{
"_index": "testindex",
"_id": "2",
"_score": 0.18232156,
"_source": {
"article_name": "The making of a glass pitcher"
}
}
]
}
}
이제 다음 boosting 쿼리를 사용해 단어 "pitcher"를 포함한 문서를 검색하되, "glass", "crystal", "water"를 포함한 문서는 가중치를 낮춰 보세요.
GET testindex/_search
{
"query": {
"boosting": {
"positive": {
"match": {
"article_name": "pitcher"
}
},
"negative": {
"match": {
"article_name": "glass crystal water"
}
},
"negative_boost": 0.1
}
}
}
두 문서 모두 여전히 반환되지만, "glass"가 포함된 문서의 관련성 점수는 이전 경우보다 10배 낮아요.
{
"took": 13,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 2,
"relation": "eq"
},
"max_score": 0.18232156,
"hits": [
{
"_index": "testindex",
"_id": "1",
"_score": 0.18232156,
"_source": {
"article_name": "The greatest pitcher in baseball history"
}
},
{
"_index": "testindex",
"_id": "2",
"_score": 0.018232157,
"_source": {
"article_name": "The making of a glass pitcher"
}
}
]
}
}
파라미터 (Parameters)
다음 표는 boosting 쿼리가 지원하는 모든 최상위 파라미터를 나열해요.
| 파라미터 | 설명 |
|---|---|
positive |
문서가 결과에 반환되기 위해 일치해야 하는 쿼리. 필수. |
negative |
결과의 문서가 이 쿼리와 일치하면, 원래 관련성 점수(positive 쿼리가 산출한)에 negative_boost 파라미터를 곱해 관련성 점수를 줄임. 필수. |
negative_boost |
negative 쿼리와 일치하는 문서의 관련성을 줄이기 위해 원래 관련성 점수에 곱하는 0과 1.0 사이의 부동소수점 계수. 필수. |