Elasticsearch: find closest/nearest docs in reference to one (calculated from known date)

Is there a standard seach possibility to find closest docs to one reference doc by date criteria (if I don not know range yet)

Example dataset

index “person”
 - doc : name=>Alice birthday=>01.01.1991
 - doc : name=>Bobby birthday=>01.01.1963
 - doc : name=>Karen birthday=>01.01.2006
 - doc : name=>James birthday=>01.01.1998
 - doc : name=>Chris birthday=>01.01.2000
 - doc : name=>Diana birthday=>01.01.2022
 - doc : name=>Wendy birthday=>01.01.1992

Find closest to James (2 precedent and 2 following from James' birthdate).

Result would be

 1. Alice (91) -2
 2. Wendy (93) -1
 3. James (98) 0
 4. Chris (00) 1
 5. Karen (06) 2 

Or a hint/example/direction how would you solve it.

1 Like

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