# NOT RUN {
(x <- connect())
x$ping()
omdb <- system.file("examples", "omdb.json", package = "elastic")
omdb <- type_remover(omdb)
if (!index_exists(x, "omdb")) invisible(docs_bulk(x, omdb))
# can be sent without a body
docs_update_by_query(x, index='omdb')
# update
## note this works with imdbRating, a float, but didn't seem to work
## with Metascore, a long
## See link above for Painless API reference
body <- '{
"script": {
"source": "ctx._source.imdbRating++",
"lang": "painless"
},
"query": {
"match": {
"Rated": "R"
}
}
}'
Search(x, "omdb", q = "Rated:\"R\"", asdf=TRUE,
source = c("Title", "Rated", "imdbRating"))$hits$hits
docs_update_by_query(x, index='omdb', body = body)
Search(x, "omdb", q = "Rated:\"R\"", asdf=TRUE,
source = c("Title", "Rated", "imdbRating"))$hits$hits
# }
Run the code above in your browser using DataLab