I have three fields:
- date_start (type: date)
- date_end (type: date)
- permanent (type: bool)
I would like to return all documents with theses conditions:
date_start <= now AND date_end >= now
OR
date_start <= now AND permanent == true
What is the best way to do that ?
I thought it would be to use a script like this :
{
"query": {
"bool": {
"filter": [
{
"script": {
"script": {
"source": "((doc['date_start'].value <= params.now) && (doc['date_end'].value >= params.now)) || ((doc['date_start'].value <= params.now) && (doc['permanent'].value == params.permanent))"
},
"lang": "painless",
"params": {
"now": "1594390526",
"permanent": true
}
}
}
]
}
}
}
But there is an issue with date types comparison and I don't know how to solve this.
Thank you
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…