ropensci / elastic

R client for the Elasticsearch HTTP API
https://docs.ropensci.org/elastic
Other
245 stars 58 forks source link

How to use docs_bulk for Bulk Deletion #183

Closed psramkumar closed 5 years ago

psramkumar commented 7 years ago

curl -XDELETE $elastic_search_index_url/_query -d '{ "query" : { "bool": { "must_not": [ { "term": { "createDate": "'$current_date'" } } ] } }}'

i would like to do the above Operation, to Delete n number of rows. please guide me the possibility,

Note: as the Document says docs_bulk is used for all CURD in bulk.

sckott commented 7 years ago

@psramkumar Can you point me to the docs for what you are describing. I've not heard of deleting in bulk with a query

in bulk operations, you have to always as far as i know provide a NDJSON structured blob https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html

psramkumar commented 7 years ago

check for this line in the link you provided, it says The possible actions are index, create, delete and update. index and create exp ...

what is that delete mean in this document.

sckott commented 7 years ago

To delete the given record, as you'd guess - did you try any of the examples in elastic::docs_bulk

psramkumar commented 7 years ago

i do not see any Example provided for bulk Delete in El Document

sckott commented 7 years ago

the examples in this package we are talking about here right now - in R, go to the help page, by running ?elastic::docs_bulk

pieterprovoost commented 7 years ago

I don't think docs_bulk currently supports delete or update, only index. See https://github.com/ropensci/elastic/blob/master/R/docs_bulk_utils.R#L9

metadata_fmt <- if (es_ids) {
  '{"index":{"_index":"%s","_type":"%s"}}'
} else {
  if (is.character(counter)) {
    '{"index":{"_index":"%s","_type":"%s","_id":"%s"}}'
  } else {
    '{"index":{"_index":"%s","_type":"%s","_id":%s}}'
  }
}
sckott commented 7 years ago

@pieterprovoost right, thanks for pointing that out.

you can create your own file with bulk operations and use that with docs_bulk - but no way to do from a data.frame or list at the moment.

I've toyed with allowing to set different operations with data.frame or list input https://github.com/ropensci/elastic/issues/169 but no progress yet

sckott commented 5 years ago

done