# Combining multi\_match with boosting

**URL:** <https://discuss.elastic.co/t/combining-multi-match-with-boosting/24058>\
**Category:** Elasticsearch\
**Created:** [June 22, 2015, 7:33am UTC](https://discuss.elastic.co/t/combining-multi-match-with-boosting/24058 "2015-06-22T07:33:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![madmuffin](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@madmuffin](https://discuss.elastic.co/u/madmuffin)\
**Post date:** [June 22, 2015, 7:33am UTC](https://discuss.elastic.co/t/combining-multi-match-with-boosting/24058/1 "2015-06-22T07:33:14Z")

</div>

Hi,

I'm new to elasticsearch and still trying to figure out the query dsl. What a lot a features!

I need to look for two strings in two fields, I found this to be working pretty well:

```
{"multi_match":{"query":"keyword1 keyword2","type":"best_fields","fields":["field1", "field2"],"tie_breaker":1}}

```

now, what I cannot figure out is how to rank matches higher, if field2 is missing. I found this option, which is supposedly what I am looking for.

```
{"boosting":{"negative":{"constant_score":{"filter":{"missing":{"field":"field2"}}}},"negative_boost":3}}

```

Unfortunately, when I combine the two, all I get is `ElasticsearchParseException[Expected field name but got START_OBJECT "0"]`.

Any hints? Cheers.

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [June 22, 2015, 8:10am UTC](https://discuss.elastic.co/t/combining-multi-match-with-boosting/24058/2 "2015-06-22T08:10:56Z")

</div>

> [@madmuffin](#):
>
> Unfortunately, when I combine the two, all I get is ElasticsearchParseException[Expected field name but got START\_OBJECT "0"].

Could you show us the full query you are sending to Elasticsearch? It's hard to comment on why you get the error without knowing the complete query you are running.

---

<div class="post-metadata">

**Author:** ![madmuffin](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@madmuffin](https://discuss.elastic.co/u/madmuffin)\
**Post date:** [June 22, 2015, 8:57am UTC](https://discuss.elastic.co/t/combining-multi-match-with-boosting/24058/3 "2015-06-22T08:57:58Z")

</div>

Sure. My full query object is:

```
{
    "query": {
        "multi_match": {
            "query": "keyword1 keyword2",
            "type": "best_fields",
            "fields": [
                "field1^3",
                "field2"
            ],
            "tie_breaker": 1
        },
        "boosting": {
            "negative": {
                "constant_score": {
                    "filter": {
                        "missing": {
                            "field": "field1"
                        }
                    }
                }
            },
            "negative_boost": 0.2
        }
    }
}

```

by the way, there was a small issue in my query, now I have `ElasticsearchParseException[Expected field name but got START_OBJECT \"boosting\"];`

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [June 22, 2015, 9:15am UTC](https://discuss.elastic.co/t/combining-multi-match-with-boosting/24058/4 "2015-06-22T09:15:55Z")

</div>

This is illegal syntax because you are trying to use multiple queries without telling Elasticsearch how to combine them. The `query` object is only allowed to contain one query, so to combine multiple queries together you need to use [a `bool` query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html). This will allow you to specify how you want to combine the two queries.

HTH

---

<div class="post-metadata">

**Author:** ![madmuffin](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@madmuffin](https://discuss.elastic.co/u/madmuffin)\
**Post date:** [June 22, 2015, 2:24pm UTC](https://discuss.elastic.co/t/combining-multi-match-with-boosting/24058/5 "2015-06-22T14:24:32Z")

</div>

Sorry, I'm still not able to figure it out. I have rewritten my query into a bool, like this:

```
{
  "bool": {
    "must": {
      "multi_match": {
        "query": " keyword1 keyword2",
        "type": "best_fields",
        "fields": [
          "field1", "field2"
        ],
        "tie_breaker": 1
      }
    }
  }
}

```

but where would the boosting go? i tried adding it as a sibling to multi\_match and also to must, but neither did work.

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [June 22, 2015, 3:01pm UTC](https://discuss.elastic.co/t/combining-multi-match-with-boosting/24058/6 "2015-06-22T15:01:18Z")

</div>

If I understand what you want correct, then you want to only return documents that match the `multi_match` query but rank documents which don't have any value for `field2` highest. In which case you need to have your `multi_match` query as a `must` clause (since a document must match this criteria to be returned) and the `boosting` query as a `should` clause (since you want documents without a `field2` field to rank higher). If so, then try the following:

```auto
{
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "keyword1 keyword2",
            "type": "best_fields",
            "fields": [
              "field1^3",
              "field2"
            ],
            "tie_breaker": 1
          }
        }
      ],
      "should": [
        {
          "boosting": {
            "negative": {
              "constant_score": {
                "filter": {
                  "missing": {
                    "field": "field2"
                  }
                }
              }
            },
            "negative_boost": 0.2
          }
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![madmuffin](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@madmuffin](https://discuss.elastic.co/u/madmuffin)\
**Post date:** [June 23, 2015, 4:57pm UTC](https://discuss.elastic.co/t/combining-multi-match-with-boosting/24058/7 "2015-06-23T16:57:18Z")

</div>

thanks a lot, that really really helped me.

A note for anyone else having this issue: I also had to add a positive boosting, as only a negative boosting did not work, but I have it up and running now!

so my result looks like this:

```
{
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "keyword1 keyword2",
            "type": "best_fields",
            "fields": [
              "field1^3",
              "field2"
            ],
            "tie_breaker": 1
          }
        }
      ],
      "should": [
        {
          "boosting": {
            "negative": {
              "constant_score": {
                "filter": {
                  "missing": {
                    "field": "field2"
                  }
                }
              }
            },
            "positive": {
              "constant_score": {
                "filter": {
                  "exists": {
                    "field": "field2"
                  }
                }
              }
            },
            "negative_boost": 0.2
          }
        }
      ]
    }
  }
}
```

---

<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:** [July 6, 2017, 12:05am UTC](https://discuss.elastic.co/t/combining-multi-match-with-boosting/24058/8 "2017-07-06T00:05:51Z")

</div>


