elasticsearch - Elasticseach script_score get value from a different index -
i trying use script_score adjust scoring of particular result based on id value. works basic run. not understand how perform lookup multiplication factor based on different table. example have mysql table of id's , associated scaling factors. these factors change hourly need used @ query time rather indexing time. while table in mysql can put index how can lookup. guess similar join in mysql? below idea of i'm going for:
{ "query": { "function_score": { "functions": [ { "script_score": { "params": { "param1": 2, "param2": 3.1 }, "script": "_score * doc['id'].value in associated table" //get scaling factor of id external table/index } } ], "query": { "filtered": { "query": { "match_all": {} } } }, "boost_mode": "multiply" } }, "explain": true }
i had exact same issue. had break down 2 queries. first query es index or database table boost factors required, , second query main search query es. however, whilst constructing query built portion of dynamically data first query, setting boost factor variable data you'd pulled out in first query. seems work quite me , hasn't slowed down search process really.
a cut-down example of follows:
$searchparams['index'] = 'someindex'; $searchparams['type'] = 'sometype'; $searchparams['body']['min_score'] = 0.75; $searchparams['body']['query']['function_score'] = array( "query" => array( "term" => array("somefield"=>$query) ) ); foreach($boostfactors $id=>$factor) { $searchparams['body']['query']['function_score']['functions'][] = array( "filter" => array( "term" => array( "id" => $id ) ), "script_score" => array("script" => $factor) ); }
Comments
Post a Comment