Combining script inline and stored within the same query

Hi guys,

Is it possible to combine script inline and stored on the same query?

For example, I've got two queries: "Query 1" which calls a stored script and "Query 2" that is a dynamic script inline. How could I combine them in a single statement?

Query 1:
{
"query": {
"script": {
"script": {
"lang": "painless",
"id": "QuarterOfTheYearFilter",
"params": {
"dt_field_name": "MyDate",
"timezone":"UTC",
"reqList": ["02","04"]
}
}
}
}
}

Query 2:
{
"query": {
"script": {
"script": {
"lang": "painless",
"inline": "ZonedDateTime.ofInstant(Instant.ofEpochMilli(doc['MyField'].value), ZoneId.of('{1}')).getDayOfMonth() = '01'"
}
}
}
}

Cheers!

Hey,

you would use a bool query, that contains those two queries within a must clause (if those should be combined with an AND).

See https://www.elastic.co/guide/en/elasticsearch/reference/5.4/query-dsl-bool-query.html

--Alex

1 Like

Thanks Alex, I 'll try.

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