Need to plug a variable into a elasticsearch query
I am trying to roll my own search_after pagination query by saving the last sort values to a db and then retrieving them on the next time I run the query. Thing is if there are no sort values from the db this means this is a new query and I skip the search_after clause in my query. If I do retrieve a set of sort values from the db then I need to plug them into the query. I am having trouble with the EL statement. This is what I have:
{
"query": {
"bool": {
"must": [
{"term": {"key1": "value1"}}
],
"must_not": [
{"exists": {"key2": "value2"}}
],
"filter": [
{"range": {"@timestamp": {"lte": "now-1w"}}}
]
}
}
${search_after:isEmpty():not():ifElse(', \"search_after\": "${search_after}"', '')},
"sort": [
{"@timestamp": "asc"},
{"value3": "asc"}
]
}
The ${search_after} variable defined as '[ts int milliseconds, "a key value string"]' Including the sq brackets.
The error I am receiving is:
Unknown key for a VALUE_STRING in search_after line 15 col 20 type parsing exception
Does anyone know how to write the variable correctly?

