Learn R Programming

elastic (version 0.4.0)

docs_mget: Get multiple documents via the multiple get API.

Description

Get multiple documents via the multiple get API.

Usage

docs_mget(index = NULL, type = NULL, ids = NULL, type_id = NULL,
  index_type_id = NULL, source = NULL, fields = NULL, raw = FALSE,
  callopts = list(), verbose = TRUE, ...)

Arguments

index
Index. Required.
type
Document type. Required.
ids
More than one document id, see examples.
type_id
List of vectors of length 2, each with an element for type and id.
index_type_id
List of vectors of length 3, each with an element for index, type, and id.
source
(logical) If TRUE, return source.
fields
Fields to return from the response object.
raw
If TRUE (default), data is parsed to list. If FALSE, then raw JSON.
callopts
Curl args passed on to httr::POST.
verbose
If TRUE (default) the url call used printed to console.
...
Further args passed on to elastic search HTTP API as parameters.

Details

There are a lot of terms you can use for Elasticsearch. See here http://www.elasticsearch.org/guide/reference/query-dsl/ for the documentation.

You can pass in one of three combinations of parameters:

  • Pass in something forindex,type, andid. This is the simplest, allowing retrieval from the same index, same type, and many ids.
  • Pass in onlyindexandtype_id- this allows you to get multiple documents from the same index, but from different types.
  • Pass in onlyindex_type_id- this is so that you can get multiple documents from different indexes and different types.

Examples

Run this code
# Same index and type
docs_mget(index="shakespeare", type="line", ids=c(9,10))
tmp <- docs_mget(index="mran", type="metadata", ids=c('plyr','ggplot2'), raw=TRUE)
es_parse(tmp)
docs_mget(index="mran", type="metadata", ids=c('plyr','ggplot2'), fields='description')
docs_mget(index="mran", type="metadata", ids=c('plyr','ggplot2'), source=TRUE)

library("httr")
docs_mget(index="twitter", type="tweet", ids=1:2, callopts=verbose())

# Same index, but different types
docs_mget(index="shakespeare", type_id=list(c("scene",1), c("line",20)))
docs_mget(index="shakespeare", type_id=list(c("scene",1), c("line",20)), fields='play_name')

# Different indeces and different types
# pass in separately
docs_mget(index_type_id=list(c("shakespeare","line",1), c("plos","article",1)))

Run the code above in your browser using DataLab