# Create function to handle and find data

**URL:** <https://discuss.elastic.co/t/create-function-to-handle-and-find-data/124976>\
**Category:** Elasticsearch\
**Created:** [March 21, 2018, 12:04pm UTC](https://discuss.elastic.co/t/create-function-to-handle-and-find-data/124976 "2018-03-21T12:04:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TomTom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tomtom/32/3676_2.png) [@TomTom](https://discuss.elastic.co/u/TomTom)\
**Post date:** [March 21, 2018, 12:04pm UTC](https://discuss.elastic.co/t/create-function-to-handle-and-find-data/124976/1 "2018-03-21T12:04:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 18, 2018, 12:04pm UTC](https://discuss.elastic.co/t/create-function-to-handle-and-find-data/124976/2 "2018-04-18T12:04:32Z")

</div>

Closed on April 18, 2018, 12:04pm UTC

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