elasticsearch - Rescoring and Sorting of documents -
my goal write query rescore documents based on value of field in document. achieve using rescore query , sorting results. however, explain on query shows me sorting of documents done based on computed score , not new one.
i saw following explains couldn't use rescore , sort together.
"sometimes want show results, ordering of first documents on page affected additional rules. unfortunately cannot achieved rescore functionality. first idea points window_size parameter, parameter in fact not connected first documents on result list number of results returned on every shard. in addition window_size cannot less page size. (if less, elasticsearch silently use page size). also, 1 important thing – rescoring cannot combined sorting, because sorting done after changes introduced rescoring."
http://elasticsearchserverbook.com/elasticsearch-0-90-using-rescore/
my query is:
{ "query": { "filtered": { "query": { "bool": { "should": [ { "constant_score": { "query": { "match": { "question": { "query": "diabetes" } } }, "boost": 1 } }, { "dis_max": { "queries": [ { "constant_score": { "query": { "match": { "question": { "query": "diabetes" } } }, "boost": 0.01 } }, { "constant_score": { "query": { "match": { "answer_text": { "query": "diabetes" } } }, "boost": 0.0001 } } ] } }, { "dis_max": { "queries": [ { "constant_score": { "query": { "match_phrase": { "question_phrase": { "query": "what diabetes", "slop": 0 } } }, "boost": 100 } }, { "constant_score": { "query": { "match_phrase": { "question_phrase": { "query": "what diabetes", "slop": 1 } } }, "boost": 50 } }, { "constant_score": { "query": { "match_phrase": { "question_phrase": { "query": "what diabetes", "slop": 2 } } }, "boost": 33 } }, { "constant_score": { "query": { "match_phrase": { "question_phrase": { "query": "what diabetes", "slop": 3 } } }, "boost": 25 } }, { "constant_score": { "query": { "query_string": { "default_field": "question_group_four", "query": "what__is__diabetes" } }, "boost": 0.1 } }, { "constant_score": { "query": { "query_string": { "default_field": "question_group_five", "query": "what__is__diabetes" } }, "boost": 0.15 } }, { "constant_score": { "query": { "query_string": { "default_field": "concept_words_no_synonyms_20", "query": "what__is__diabetes" } }, "boost": 35 } }, { "constant_score": { "query": { "query_string": { "default_field": "concept_words_no_synonyms_15", "query": "what__is__diabetes" } }, "boost": 25 } }, { "constant_score": { "query": { "query_string": { "default_field": "concept_words_no_synonyms_10", "query": "what__is__diabetes" } }, "boost": 15 } }, { "constant_score": { "query": { "query_string": { "default_field": "concept_words_20", "query": "what__is__diabetes" } }, "boost": 28 } }, { "constant_score": { "query": { "query_string": { "default_field": "concept_words_15", "query": "what__is__diabetes" } }, "boost": 16 } }, { "constant_score": { "query": { "query_string": { "default_field": "concept_words_10", "query": "what__is__diabetes" } }, "boost": 13 } }, { "constant_score": { "query": { "query_string": { "default_field": "concept_words_05", "query": "what__is__diabetes" } }, "boost": 4 } } ] } }, { "dis_max": { "queries": [ { "constant_score": { "query": { "query_string": { "default_field": "question_group_four", "query": "diabetes" } }, "boost": 0.1 } }, { "constant_score": { "query": { "query_string": { "default_field": "question_group_five", "query": "diabetes" } }, "boost": 0.15 } }, { "constant_score": { "query": { "query_string": { "default_field": "concept_words_no_synonyms_20", "query": "diabetes" } }, "boost": 35 } }, { "constant_score": { "query": { "query_string": { "default_field": "concept_words_no_synonyms_15", "query": "diabetes" } }, "boost": 25 } }, { "constant_score": { "query": { "query_string": { "default_field": "concept_words_no_synonyms_10", "query": "diabetes" } }, "boost": 15 } }, { "constant_score": { "query": { "query_string": { "default_field": "concept_words_20", "query": "diabetes" } }, "boost": 28 } }, { "constant_score": { "query": { "query_string": { "default_field": "concept_words_15", "query": "diabetes" } }, "boost": 16 } }, { "constant_score": { "query": { "query_string": { "default_field": "concept_words_10", "query": "diabetes" } }, "boost": 13 } }, { "constant_score": { "query": { "query_string": { "default_field": "concept_words_05", "query": "diabetes" } }, "boost": 4 } } ] } } ], "disable_coord": true } }, "filter": { "and": [ { "term": { "posted_by_expert": false } }, { "term": { "tip_question": false } }, { "term": { "show_in_work_queue": true } }, { "range": { "verified_answers_count": { "gt": 0 } } } ] } } }, "rescore": { "window_size": 100, "query": { "rescore_query": { "function_score": { "functions": [ { "script_score": { "script": "_score * _source.concierge_boost" } } ] } } } }, "sort": [ "_score", { "count_words_with_high_concepts": { "order": "asc" } }, { "popularity": { "order": "desc" } }, { "length": { "order": "asc" } } ], "fields": [], "size": 10, "from": 0
}
any highly appreciated !
this not possible, indeed. but has been discussed , decided not worth implementing @ moment. discussion on github, though, reveals difficulty - documents need sorted, top 100 (in case) chosen, rescore applied , are, again, sorted. suggest reading comments in github issue, ones simonw
. issue still open doesn't seem implemented soon, if @ all.
regarding sorting after level of scoring, understand need rescore few documents, seems not possible. if wrap query in function_score
define script_score
function compute final score? this:
{ "query": { "function_score": { "query": { ....... }, "functions": [ { "script_score": { "script": "doc['concierge_boost'].value" } } ] } }, "sort": [ "_score", { "count_words_with_high_concepts": { "order": "asc" } }, { "popularity": { "order": "desc" } }, { "length": { "order": "asc" } } ], "fields": [], "size": 10, "from": 0 }
Comments
Post a Comment