Learn R Programming

elastic (version 0.3.0)

scroll: Scroll search function

Description

Scroll search function

Usage

scroll(scroll_id, scroll = "1m", raw = FALSE, ...)

Arguments

scroll_id
(character) Scroll id
scroll
(character) Specify how long a consistent view of the index should be maintained for scrolled search, e.g., "30s", "1m". See units-time.
raw
If TRUE (default), data is parsed to list. If FALSE, then raw JSON.
...
Curl args passed on to POST

See Also

Search

Examples

Run this code
# Get a scroll_id
res <- Search(index = 'shakespeare', q="a*", scroll="1m")
res$`_scroll_id`

# Setting search_type=scan turns off sorting of results, is faster
res <- Search(index = 'shakespeare', q="a*", scroll="1m", search_type = "scan")
res$`_scroll_id`

# Pass scroll_id to scroll function
scroll(scroll_id = res$`_scroll_id`)

# Get all results - one approach is to use a while loop
res <- Search(index = 'shakespeare', q="a*", scroll="5m", search_type = "scan")
out <- list()
hits <- 1
while(hits != 0){
  res <- scroll(scroll_id = res$`_scroll_id`)
  hits <- length(res$hits$hits)
  if(hits > 0)
    out <- c(out, res$hits$hits)
}
length(out)
out[[1]]

Run the code above in your browser using DataLab