Query documents with per term weights


(lc_es) #1

The documents in my index have a field containing a list of all attribute terms, like
"fieldA": ["attr1", "attr3", "attr7"]
and for each attribute term, a field containing its weight, like
"weight:attr1": 0.5, "weight:attr3": 0.3, "weight:attr7": 0.8].

I am using a multi_match query on the "fieldA" right now and I want to incorporate these weights into the score, so that the score of any query, document pair can be
doc["weight:attr1"] * tf-idf(query, doc, "attr1") + doc["weight:attr2"] * tf-idf(query, doc, "attr2") + ....

I am wondering how I should construct this query.

I tried using function_score but since function_score is per query I have to explicitly list out all possible "attr"s at query time which is not ideal for me.

Thanks!


(Mayya Sharipova) #2

In Elasticsearch 7.x we will have feature and feature vector data types, and together with feature query they will let you very efficiently process your request. You would be able to model your fieldA field as a feature_vector and run feature_query request on it.