# NOT RUN {
(x <- connect())
if (!index_exists(x, "shakespeare")) {
shakespeare <- system.file("examples", "shakespeare_data_.json",
package = "elastic")
shakespeare <- type_remover(shakespeare)
invisible(docs_bulk(x, shakespeare))
}
docs_get(x, index='shakespeare', id=10)
docs_get(x, index='shakespeare', id=12)
docs_get(x, index='shakespeare', id=12, source=TRUE)
# Get certain fields
if (gsub("\\.", "", x$ping()$version$number) < 500) {
### ES < v5
docs_get(x, index='shakespeare', id=10, fields='play_name')
docs_get(x, index='shakespeare', id=10, fields=c('play_name','speaker'))
} else {
### ES > v5
docs_get(x, index='shakespeare', id=10, source='play_name')
docs_get(x, index='shakespeare', id=10, source=c('play_name','speaker'))
}
# Just test for existence of the document
docs_get(x, index='plos', id=1, exists=TRUE)
docs_get(x, index='plos', id=123456, exists=TRUE)
# source includes / excludes
docs_get(x, index='shakespeare', id=10, source_includes = "play_name")
docs_get(x, index='shakespeare', id=10, source_excludes = "play_name")
# }
Run the code above in your browser using DataLab