Constant_score doesn’t returns any doc - ES 2.x

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!

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

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

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