Get surrounding documents vía API

Hello!

Is there any way to replicate "Surrounding Documents" function from Kibana but via API?

I'm trying different ways, but none is working (span_near, scroll API...).

Any help is appreciated!

Hi @elasticUser5
If you take a look at that Kibana do when requesting the surrounding documents, you can find that we are doing 3 searches:

  1. get the specific document
  2. get a max of 5 documents that are 1 day older then the date of the retrieved document at (1)
  3. get a max o 5 documents that are 1 day after then the date of the retrieved document at (1)

remember to sort the documents request by the timestamp to get them in the correct order and use the https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#request-body-search-search-after

1 Like