# Script Query returns no hits in 5.5

**URL:** <https://discuss.elastic.co/t/script-query-returns-no-hits-in-5-5/94182>\
**Category:** Elasticsearch\
**Created:** [July 22, 2017, 1:38am UTC](https://discuss.elastic.co/t/script-query-returns-no-hits-in-5-5/94182 "2017-07-22T01:38:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Toady00](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/toady00/32/20332_2.png) [@Toady00](https://discuss.elastic.co/u/Toady00)\
**Post date:** [July 22, 2017, 1:38am UTC](https://discuss.elastic.co/t/script-query-returns-no-hits-in-5-5/94182/1 "2017-07-22T01:38:30Z")

</div>

**Nevermind, after a couple of hours of beating my head, as soon as I posted this I saw my problem. Wrong type!**

I have a document with two fields, "size" and "matched\_size". I want to return all documents where the "matched\_size" is less than the "size" field. I pulled this example from [the docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-script-query.html).

```auto
GET trades-temp/trades/_search
{
  "query": {
    "bool": {
      "must": {
        "script": {
          "script": {
            "inline": "doc['matched_size'].value < doc['size'].value",
            "lang": "painless"
          }
        }
      }
    }
  }
}

```

Returns:

```auto
{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}

```

But I know it should return something since

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

```

returns:

```auto
{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 2,
    "successful": 2,
    "failed": 0
  },
  "hits": {
    "total": 2,
    "max_score": 1,
    "hits": [
      {
        "_index": ".kibana",
        "_type": "config",
        "_id": "5.5.0",
        "_score": 1,
        "_source": {
          "buildNum": 15382
        }
      },
      {
        "_index": "trades-temp",
        "_type": "trade",
        "_id": "AV1n03zZZi4H5W5T31qu",
        "_score": 1,
        "_source": {
          "price": 2500,
          "size": 1,
          "matched_size": 0
        }
      }
    ]
  }
}

```

Which obviously should match the script. What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![panda2004](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/panda2004/32/19473_2.png) [@panda2004](https://discuss.elastic.co/u/panda2004)\
**Post date:** [July 22, 2017, 10:59pm UTC](https://discuss.elastic.co/t/script-query-returns-no-hits-in-5-5/94182/2 "2017-07-22T22:59:02Z")

</div>

both of them are shown as numeric in the mapping?

---

<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:** [August 19, 2017, 10:59pm UTC](https://discuss.elastic.co/t/script-query-returns-no-hits-in-5-5/94182/3 "2017-08-19T22:59:09Z")

</div>

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