# Constant\_score doesn’t returns any doc - ES 2.x

**URL:** <https://discuss.elastic.co/t/constant-score-doesn-t-returns-any-doc-es-2-x/78025>\
**Category:** Elasticsearch\
**Created:** [March 9, 2017, 4:59pm UTC](https://discuss.elastic.co/t/constant-score-doesn-t-returns-any-doc-es-2-x/78025 "2017-03-09T16:59:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Infrid](https://avatars.discourse-cdn.com/v4/letter/i/db5fbb/32.png) [@Infrid](https://discuss.elastic.co/u/Infrid)\
**Post date:** [March 9, 2017, 4:59pm UTC](https://discuss.elastic.co/t/constant-score-doesn-t-returns-any-doc-es-2-x/78025/1 "2017-03-09T16:59:49Z")

</div>

Hello,

I am writing a `dis_max` query for stacking up the results from different queries. The first query usually returns only one result and I'd like to have that document on top on my results. So I put the query inside a `constant_score` with a bigger score.

```
{
  "query": {
    "constant_score": {
      "query": {
        "bool": {
          "must": [
            {
              "match_phrase": {
                "article_title": {
                  "query": "elasticsearch server",
                  "slop": 60
                }
              }
            }
          ],
          "should": [
            {
              "match": {
                "article_title.raw": "elasticsearch server"
              }
            }
          ],
          "filter": [
            {
              "term": {
                "article_status": "publish"
              }
            },
            {
              "term": {
                "article_type": "document"
              }
            }
          ]
        }
      },
      "boost": 3
    }
  }
}

```

This query doesn’t return any results, but if I remove `constant_score` and execute the query again I get my expected results. So I think the proble is not the query but how I use `constant_score`.

As fas I know `constant_score` should return the document from the inner query, does the query looks ok?

Anyway here my complete query, maybe my approach is not great, right?

```
{
  "query": {
    "dis_max": {
      "tie_breaker": 0.7,
      "queries": [
        {
          "query": {
            "constant_score": {
              "query": {
                "bool": {
                  "must": [
                    {
                      "match_phrase": {
                        "article_title": {
                          "query": "elasticsearch server",
                          "slop": 60,
                          "operator": "and",
                          "minimum_should_match": "80%"
                        }
                      }
                    }
                  ],
                  "should": [
                    {
                      "match": {
                        "article_title.raw": "elasticsearch server"
                      }
                    }
                  ],
                  "filter": [
                    {
                      "term": {
                        "article_status": "publish"
                      }
                    },
                    {
                      "term": {
                        "article_type": "acumen"
                      }
                    }
                  ]
                }
              },
              "boost": 20
            }
          }
        },
        {
          "query": {
            "bool": {
              "must": [
                {
                  "match_phrase": {
                    "article_title": {
                      "query": "elasticsearch server",
                      "operator": "and",
                      "minimum_should_match": "60%",
                      "slop": 30
                    }
                  }
                }
              ],
              "should": [
                {
                  "range": {
                    "article_date": {
                      "gt": "2017-01-01 00:00:00"
                    }
                  }
                }
              ]
            }
          }
        },
        {
          "query": {
            "bool": {
              "must": [
                {
                  "match_phrase": {
                    "article_content": {
                      "query": "elasticsearch server",
                      "slop": "70"
                    }
                  }
                }
              ],
              "should": [
                {
                  "range": {
                    "article_date": {
                      "gt": "2017-01-01 00:00:00"
                    }
                  }
                }
              ]
            }
          }
        }
      ]
    }
  }
}

```

I am using Elasticsearch 2.4.4 and oracle Java 1.8.0\_121  
Thanks!

---

<div class="post-metadata">

**Author:** ![Infrid](https://avatars.discourse-cdn.com/v4/letter/i/db5fbb/32.png) [@Infrid](https://discuss.elastic.co/u/Infrid)\
**Post date:** [March 10, 2017, 12:06pm UTC](https://discuss.elastic.co/t/constant-score-doesn-t-returns-any-doc-es-2-x/78025/2 "2017-03-10T12:06:34Z")

</div>

```
           {
              "match": {
                "article_title.raw": "elasticsearch server"
              }
            }

```

found the problem, was on my data, not the query.

---

<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 7, 2017, 12:06pm UTC](https://discuss.elastic.co/t/constant-score-doesn-t-returns-any-doc-es-2-x/78025/3 "2017-04-07T12:06:45Z")

</div>

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