I think the issue you are running into is that the essql function only accepts something of type filter as input (because it applies any global filters to the query), and the context is different by the time you get to the lte function (it's the number returned from getCell "foo"), so essql doesn't know what to do with it -- which explains the cryptic Can not cast number to any of filter error.
The reason most of our data fetching functions are set up this way is because they originally assumed that generally, fetching data was going to happen at the beginning of an expression instead of in the middle. Obviously this is an assumption we should revisit, because yours is a perfectly valid use case.
In the meantime, a workaround would be to use the var and var_set functions, which can be used to store globals that are accessible later in the expression. In your case, it would look something like this:
filters group="default"
| var_set name="index2Count" value={essql query="select count(*) from \"index2*\" " | head 1 | getCell "count"}
| essql
query="select SUM(foo) as foo_total from \"index*\" "
| head 1
| if { context | head 1 | getCell "foo" | lte {var "index2Count"} } then={markdown "True" | render} else={markdown "False" | render}
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.