tf idf - Elasticsearch function_score query -
i'm using elasticsearch v 1.7.3
here fields in document:
field1, field2, field3, field4
i need give weightage each field field1: 40, field2: 40, field3: 10, field4: 10
during indexing, field1 , field2 expanded phonetic tokens. have field1 ==> field1, field1.1, field1.2 , field2 => field2, field2.1, field2.2
my query can based on combination of of above 4 fields.
now scoring, don't want use tf/idf or bm25 scoring models.
rather want compute weighted average per field , sum them together.
for example input query: field1: abc field2: pqr field3: xyz field4: rst
assume there following documents in corpus:
document 1 ----------- field1: abc field2: pqr field3: xyz field4: rst document 2 ----------- field1: abx field2: pqr field3: xyz field4: rst
score document 1: 100 ==> weightedaverage(field1) + weightedaverage(field2) + weightedaverage(field3) + weightedaverage(field4) ===> 40 + 40 + 10 + 10
score document 2: 90 ==> weightedaverage(field1) + weightedaverage(field2) + weightedaverage(field3) + weightedaverage(field4) ===> 30 + 40 + 10 + 10 (not hope idea).
can in function_score query? couldn't quite how can accomplished. thanks.
you need take @ function score query.inside function score , define boolean query filters on each of field , assgin boost(40 or 10) , choose boost_mode sum.
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html
{ "functions": [ { "filter": { "query": { "bool": { "should": [ { "match": { "inputloc1": "abc" } } ] } } }, "boost_factor": 11 }, { "filter": { "query": { "bool": { "should": [ { "query_string": { "fields": [ "input" ], "query": "xyz", "fuzziness": 0, "fuzzy_prefix_length": 0 } } ] } } }, "boost_factor": 6 } ], "boost_mode": "sum" }
i gave example function code, can switch query match(instead of query strings).what define inside function computes score.what define inside query(inside function_score filter documents).
hope helps.
Comments
Post a Comment