# Using constant\_score combined with multi\_match cross\_field

**URL:** <https://discuss.elastic.co/t/using-constant-score-combined-with-multi-match-cross-field/123487>\
**Category:** Elasticsearch\
**Created:** [March 12, 2018, 6:50am UTC](https://discuss.elastic.co/t/using-constant-score-combined-with-multi-match-cross-field/123487 "2018-03-12T06:50:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahmadazimi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmadazimi/32/25247_2.png) [@ahmadazimi](https://discuss.elastic.co/u/ahmadazimi)\
**Post date:** [March 12, 2018, 6:50am UTC](https://discuss.elastic.co/t/using-constant-score-combined-with-multi-match-cross-field/123487/1 "2018-03-12T06:50:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Ahmed\_Tarek](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@Ahmed\_Tarek](https://discuss.elastic.co/u/Ahmed_Tarek)\
**Post date:** [March 26, 2018, 4:17pm UTC](https://discuss.elastic.co/t/using-constant-score-combined-with-multi-match-cross-field/123487/2 "2018-03-26T16:17:07Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 23, 2018, 4:17pm UTC](https://discuss.elastic.co/t/using-constant-score-combined-with-multi-match-cross-field/123487/3 "2018-04-23T16:17:39Z")

</div>

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