Используемые свойства:
{
"mappings": {
"properties": {
"attribute_must_1": {
"type": "nested"
},
"attribute_1": {
"type": "nested"
},
"attribute_2": {
"type": "nested"
},
}
}
}
Входные документы для тестирования:
POST _bulk
{"index":{"_index":"scores","_type":"_doc"}}
{"attribute_must_1":{"id":1},"attribute_1":{"id":9},"attribute_2":{"id":3}}
{"index":{"_index":"scores","_type":"_doc"}}
{"attribute_must_1":{"id":1},"attribute_1":{"id":9},"attribute_2":{"id":3}}
{"index":{"_index":"scores","_type":"_doc"}}
{"attribute_must_1":{"id":1},"attribute_1":{"id":8},"attribute_2":{"id":3}}
{"index":{"_index":"scores","_type":"_doc"}}
{"attribute_must_1":{"id":1},"attribute_1":{"id":7},"attribute_2":{"id":3}}
{"index":{"_index":"scores","_type":"_doc"}}
{"attribute_must_1":{"id":1},"attribute_1":{"id":11},"attribute_2":{"id":3}}
{"index":{"_index":"scores","_type":"_doc"}}
{"attribute_must_1":{"id":1},"attribute_1":{"id":5},"attribute_2":{"id":3}}
{"index":{"_index":"scores","_type":"_doc"}}
{"attribute_must_1":{"id":1},"attribute_1":{"id":10},"attribute_2":{"id":3}}
{"index":{"_index":"scores","_type":"_doc"}}
{"attribute_must_1":{"id":1},"attribute_1":{"id":6},"attribute_2":{"id":3}}
{"index":{"_index":"scores","_type":"_doc"}}
{"attribute_must_1":{"id":1},"attribute_1":{"id":7},"attribute_2":{"id":3}}
{"index":{"_index":"scores","_type":"_doc"}}
{"attribute_must_1":{"id":1},"attribute_1":{"id":7},"attribute_2":{"id":3}}
Фактический запрос:
q = {
"size": 10,
"query": {
"function_score": {
"query": {
"bool": {
"filter": [
],
"must": [
{
"nested": {
"path": "attribute_must_1",
"query": {
"term": {
"attribute_must_1.id": "1"
}
}
}
}
]
}
},
"boost": 1,
"functions": [
{
"filter": {
"nested": {
"path": "attribute_1",
"query": {
"script_score": {
"query": {
"match_all": {}
},
"script": {
"source": "decayNumericLinear(params.origin, params.scale, params.offset, params.decay, doc['attribute_1.id'].value)",
"params": {
"origin": 10,
"scale": 5,
"decay": 2,
"offset": 0
}
}
}
},
}
},
"weight": 30
},
{"filter": {"nested": {"path": "attribute_2", "query": {"term": {"attribute_2.id": "3"}}}}, "weight": 70},
],
"score_mode": "sum",
"boost_mode": "replace"
}
},
"sort": [
"_score",
{
"date_deposit": {
"order": "desc"
}
}
]
}
Я пытаюсь добавить новый фильтр с вложенным полем "attribute_1", где я хочу вычислить расстояние между фактическим значением и значением из всех других документов, но это не влияет на оценки, которые я вижу:
для атрибута_1 найденного:
документов = [9, 9, 9, 10, 9, 9, 4, 9, 3, 9]
Я получаю (сумма 30% и 70 % весов из 2 атрибутов):
оценки = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100]
, поэтому он кажется довольно двоичным, хотя должен быть каким-то образом линейной функцией. Что я хочу примерно так:
для найденных значений документов: [10, 9, 8, 3, 10] и входное значение 10 -> Я хотел бы иметь:
оценки (скажем, в процентах): [100%, 90%, 80%, 30%, 100%]
Я хотел бы получить простой результат в диапазоне от 0 до 100%, но включая частичные оценки по нескольким атрибутам (attribute_1, attribute_2, ...) таким образом, что:
- оценка из attribute_1 в линейной оценке на основе расстояния (т.е. любое значение от 0% до 30%)
- оценка по атрибуту_2 составляет 0% или 70% (запрос термина)
Я пробовал разные варианты, но ничего не работает - как правильно это сделать? У меня такое впечатление, что запрос filter
не может каким-то образом выполнить script_scores ...
Надеюсь, кто-нибудь может мне с этим помочь? Огромный THNX!