[script] query does not support [params]

Hello,
I'm trying to perform a scripted query:

{
  "query": {
    "bool": {
      "must": [
        {
          "script": {
            "script": "doc['@timestamp'].value.hourOfDay >= params.startHour && doc['@timestamp'].value.hourOfDay <= params.endHour",
            "params": {
              "startHour": 10,
              "endHour": 11
            }
          }
        }
      ]
    }
  }
}

But get this error:

{
  "error": {
    "root_cause": [
      {
        "type": "parsing_exception",
        "reason": "[script] query does not support [params]",
        "line": 8,
        "col": 23
      }
    ],
    "type": "parsing_exception",
    "reason": "[script] query does not support [params]",
    "line": 8,
    "col": 23
  },
  "status": 400
}

Everything works with hardcoded values:

{
  "query": {
    "bool": {
      "must": [
        {
          "script": {
            "script": "doc['@timestamp'].value.hourOfDay >= 10 && doc['@timestamp'].value.hourOfDay <= 11"
          }
        }
      ]
    }
  }
}

Do you have any clues?

Thanks,
Lorenzo

When you use params, you need to do it like this

{
  "query": {
    "bool": {
      "must": [
        {
          "script": {
            "script": {
               "source": "doc['@timestamp'].value.hourOfDay >= params.startHour && doc['@timestamp'].value.hourOfDay <= params.endHour",
               "params": {
                 "startHour": 10,
                 "endHour": 11
               }
            }
          }
        }
      ]
    }
  }
}

Thanks!
Works like charm :slight_smile:

Awesome, glad it helped :wink:

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