# Query time boosting produces result in inadequate order

**URL:** <https://discuss.elastic.co/t/query-time-boosting-produces-result-in-inadequate-order/50764>\
**Category:** Elasticsearch\
**Created:** [May 23, 2016, 8:20pm UTC](https://discuss.elastic.co/t/query-time-boosting-produces-result-in-inadequate-order/50764 "2016-05-23T20:20:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![BentCoder](https://avatars.discourse-cdn.com/v4/letter/b/c4cdca/32.png) [@BentCoder](https://discuss.elastic.co/u/BentCoder)\
**Post date:** [May 23, 2016, 8:20pm UTC](https://discuss.elastic.co/t/query-time-boosting-produces-result-in-inadequate-order/50764/1 "2016-05-23T20:20:53Z")

</div>

The ES search result for the given search keyword `one two three` seems to be wrong after applying `boost` feature per keyword. Please help me modifying my "faulty" query in order to accomplish "expected result" below as I described. I'm on ES 1.7.4 with LUCENE 4.10.4

Original question is here in [stackoverflow](http://stackoverflow.com/questions/37372951/elasticsearch-query-time-boosting-produces-result-in-inadequate-order?noredirect=1#comment62264775_37372951).

**Boosting criteria**

```
word - boost
---- -----
one 1
two 2
three 3

```

**ES index content** - _just showing MySQL dump to make the post shorter_

```
mysql> SELECT id, title FROM post;
+----+-------------------+
| id | title |
+----+-------------------+
| 1 | one |
| 2 | two |
| 3 | three |
| 4 | one two |
| 5 | one three |
| 6 | one two three |
| 7 | two three |
| 8 | none |
| 9 | one abc |
| 10 | two abc |
| 11 | three abc |
| 12 | one two abc |
| 13 | one two three abc |
| 14 | two three abc |
+----+-------------------+
14 rows in set (0.00 sec)

```

**Expected ES query result** - _The user is searching for_ `one two three`. _I'm not fussed about the order of equally scored records. I mean if record 6 and 13 switches places, I don't mind._

```
+----+-------------------+
| id | title | my scores for demonstration purposes
+----+-------------------+
| 6 | one two three | (1+2+3 = 6)
| 13 | one two three abc | (1+2+3 = 6)
| 7 | two three | (2+3 = 5)
| 14 | two three abc | (2+3 = 5)
| 5 | one three | (1+3 = 4)
| 4 | one two | (1+2 = 3)
| 12 | one two abc | (1+2 = 3)
| 3 | three | (3 = 3)
| 11 | three abc | (3 = 3)
| 2 | two | (2 = 2)
| 10 | two abc | (2 = 2)
| 1 | one | (1 = 1)
| 9 | one abc | (1 = 1)
| 8 | none | <- This shouldn't appear
+----+-------------------+
14 rows in set (0.00 sec)

```

**Unexpected ES query result** - _Unfortunately, This is what I get._

```
+----+-------------------+
| id | title | _score
+----+-------------------+
| 6 | one two three | 1.0013864
| 13 | one two three abc | 1.0013864
| 4 | one two | 0.57794875
| 3 | three | 0.5310148
| 7 | two three | 0.50929534
| 5 | one three | 0.503356
| 14 | two three abc | 0.4074363
| 11 | three abc | 0.36586377
| 12 | one two abc | 0.30806428
| 10 | two abc | 0.23231897
| 2 | two | 0.12812772
| 1 | one | 0.084527075
| 9 | one abc | 0.07408653
+----+-------------------+

```

**ES query**

```
curl -XPOST "http://127.0.0.1:9200/_search?post_dev" -d'
{
  "query": {
    "bool": {
      "must": {
        "match": {
          "title": {
            "query": "one two three"
          }
        }
      },
      "should": [
        {
          "match": {
            "title": {
              "query": "one",
              "boost": 1
            }
          }
        },
        {
          "match": {
            "title": {
              "query": "two",
              "boost": 2
            }
          }
        },
        {
          "match": {
            "title": {
              "query": "three",
              "boost": 3
            }
          }
        }
      ]
    }
  },
  "sort": [
    {
      "_score": {
        "order": "desc"
      }
    }
  ],
  "from": "0",
  "size": "100"
}'
```

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [May 24, 2016, 10:28am UTC](https://discuss.elastic.co/t/query-time-boosting-produces-result-in-inadequate-order/50764/2 "2016-05-24T10:28:19Z")

</div>

Hi @BentCoder,

you give too little information to reproduce this but scoring does not only take your boost value into account. From the [reference documentation](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/index-boost.html):

> The default relevance calculation takes field length into account, so a short[...] field will have a higher natural boost than a long [...] field.

You can use [explain](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/search-request-explain.html#search-request-explain) to get more details how the final score has been computed by Elasticsearch.

Suppose your original query is (I don't use your query but a much shorter one so you see the difference more easily):

```auto
GET /myindex/_search
{
    "query": {
        "match_all": {}
    }
}

```

then you can get an explanation of the score calculation by adding `"explain": true` in the body:

```auto
GET /myindex/_search
{
    "explain": true, 
    "query": {
        "match_all": {}
    }
}

```

Daniel

---

<div class="post-metadata">

**Author:** ![BentCoder](https://avatars.discourse-cdn.com/v4/letter/b/c4cdca/32.png) [@BentCoder](https://discuss.elastic.co/u/BentCoder)\
**Post date:** [May 24, 2016, 10:57am UTC](https://discuss.elastic.co/t/query-time-boosting-produces-result-in-inadequate-order/50764/3 "2016-05-24T10:57:14Z")

</div>

Hi @danielmitterdorfer ,

Thank you for the answer. Later on I'll attach `explain` details to provide more data (_I don't have the test case with me at the moment_).

Based on the length calculation I understand the order a bit more now but what I don't understand is why 7, 5 and 14 comes after 4 and 3 as show below.

```
+----+-------------------+
| id | title | _score	- my points
+----+-------------------+
| 6 | one two three | 1.0013864	- 6
| 13 | one two three abc | 1.0013864	- 6
| 4 | one two | 0.57794875	- 3
| 3 | three | 0.5310148	- 3
| 7 | two three | 0.50929534	- 5
| 5 | one three | 0.503356	- 4
| 14 | two three abc | 0.4074363	- 5
| 11 | three abc | 0.36586377	- 3
| 12 | one two abc | 0.30806428	- 3
| 10 | two abc | 0.23231897	- 2
| 2 | two | 0.12812772	- 2
| 1 | one | 0.084527075	- 1
| 9 | one abc | 0.07408653	- 1
+----+-------------------+

```

Some more test queries:

- This [query](http://pastebin.com/G5DLpfb7) doesn't produce any result.
- This [query](http://pastebin.com/HTCvLGvp) doesn't order correctly as seem [here](http://pastebin.com/BHcnZQti).

Thank you very much

---

<div class="post-metadata">

**Author:** ![BentCoder](https://avatars.discourse-cdn.com/v4/letter/b/c4cdca/32.png) [@BentCoder](https://discuss.elastic.co/u/BentCoder)\
**Post date:** [May 24, 2016, 6:21pm UTC](https://discuss.elastic.co/t/query-time-boosting-produces-result-in-inadequate-order/50764/4 "2016-05-24T18:21:32Z")

</div>

It has been solved now. Solution is in stackoverflow link above.

---

<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 5, 2017, 10:49pm UTC](https://discuss.elastic.co/t/query-time-boosting-produces-result-in-inadequate-order/50764/5 "2017-07-05T22:49:24Z")

</div>


