Using constant_score combined with multi_match cross_field

I've tried to use cross_field query to search over multiple fields with completely different boosts. But TF/IDF makes the results so bad because I just want to see if a term exist in the fields or not (but if exists, apply each field's boost to calculate the final score). Unfortunately when I use constant_score to disable TF/IDF on my multi_match query, all boosts ignored.

can anyone help me to write a correct query for this situation?

What you can do is wrapping the multi_match query in filter query inside function_score query with a weight.

function_score: {
	boost_mode: "sum",
	weight:     "3.0",
	query: {
		bool: {
			filter: {
				multi_match: {
					query: "test",
					fields: [:field_1, :field_2, :field3],
					type: "cross_fields",
					operator: "and"

So the idea here that the filter does not contribute to the score (query_score = 0).

The function_score is 3, calculated as such:
A constant score of 1 (because no function is provided) * 3 (which is the weight).

Therefore the final score of the function_score query would be calculated as follows

Score = 0 + (3*1) = 3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.