Create function to handle and find data

Currently in my mapping i have two properties:

1 - deadline: type date, store a datetime to know what is the deadline of a project
2 - current_stats: type long, store if the status of a project is opened (1), closed (5) or canceled (4).

In my PostgreSQL I have a function that handles this data and returns whether the deadline was expired or not, like the code below:

IF (deadline IS NULL) THEN
--WITHOUT DEADLINE
RETURN 2;
ELSIF
(
((current_stats IN (4, 5)) AND (deadline >= current_timestamp))
)
THEN
--UNEXPIRED DEADLINE
RETURN 1;
ELSIF
(
((current_stats NOT IN (4, 5)) AND (deadline < datahora))
)
THEN
--EXPIRED DEADLINE
RETURN 0;
ELSIF
(
((current_stats IN (4, 5)) AND (deadline < current_timestamp))
)
THEN
--EXPIRED DEADLINE
RETURN 0;
ELSIF
(
((current_stats NOT IN (4, 5)) AND (deadline >= current_timestamp))
)
THEN
--UNEXPIRED DEADLINE
RETURN 1;
ELSIF
(
((current_stats NOT IN (4, 5)) AND (deadline < current_timestamp))
)
THEN
--EXPIRED DEADLINE
RETURN 0;
END IF;

Is possible create something like that in Elasticsearch to find data using the function?

Example:

"bool": {
"term": [
{
function_deadline_ok(deadline, current_stats): 1
}
]
}

It is not possible to set this value at indexing time because it can change during the day and this will require reindexing every project every minute.

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