# NOT RUN {
(x <- connect())
x$ping()
plosdat <- system.file("examples", "plos_data.json",
package = "elastic")
plosdat <- type_remover(plosdat)
if (!index_exists(x, "plos")) invisible(docs_bulk(x, plosdat))
# delete with fuzzy matching
body <- '{
"query": {
"match": {
"title": {
"query": "cells",
"fuzziness": 1
}
}
}
}'
docs_delete_by_query(x, index='plos', body = body)
# delete with no fuzziness
if (index_exists(x, "plos")) index_delete(x, 'plos')
invisible(docs_bulk(x, plosdat))
count(x, "plos")
body <- '{
"query": {
"match": {
"title": {
"query": "cells",
"fuzziness": 0
}
}
}
}'
docs_delete_by_query(x, index='plos', body = body)
# delete all docs with match_all query
if (index_exists(x, "plos")) index_delete(x, 'plos')
invisible(docs_bulk(x, plosdat))
body <- '{
"query": {
"match_all": {}
}
}'
docs_delete_by_query(x, index='plos', body = body)
# put plos back in
if (index_exists(x, "plos")) index_delete(x, 'plos')
invisible(docs_bulk(x, plosdat))
# delete docs from more than one index
foo <- system.file("examples/foo.json", package = "elastic")
if (!index_exists(x, "foo")) invisible(docs_bulk(x, foo))
bar <- system.file("examples/bar.json", package = "elastic")
if (!index_exists(x, "bar")) invisible(docs_bulk(x, bar))
body <- '{
"query": {
"match_all": {}
}
}'
docs_delete_by_query(x, index=c('foo','bar'),
body = body, verbose = TRUE)
# }
Run the code above in your browser using DataLab