[script] query does not support [params]


(Lorenzo Brutti) #1

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


(Val Crettaz) #2

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
               }
            }
          }
        }
      ]
    }
  }
}

(Lorenzo Brutti) #3

Thanks!
Works like charm :slight_smile:


(Val Crettaz) #4

Awesome, glad it helped :wink:


(system) #5

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