Script Query returns no hits in 5.5


(Brandon Dennis) #1

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.

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

Returns:

{
  "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

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

returns:

{
  "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?


#2

both of them are shown as numeric in the mapping?


(system) #3

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