Reputation: 1082
This is my code:
HTTParty.delete("http://#{SERVER_DOMAIN}:9200/monitoring/mention_reports/_query?q=id:11321779,11321779", {
})
I want to delete data in bulk using id but this query is not deleting data from elasticsearch
Can anyone help me figuring out how can I delete data in bulk?
Upvotes: 0
Views: 2150
Reputation: 979
Provision is provided using: https://www.elastic.co/guide/en/elasticsearch/reference/1.4/docs-bulk.html
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_type" : "type1", "_id" : "2" } }
{ "create" : { "_index" : "test", "_type" : "type1", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_id" : "1", "_type" : "type1", "_index" : "index1"} }
{ "doc" : {"field2" : "value2"} }
OR
curl -XPOST 'localhost:9200/customer/external/_bulk?pretty' -d '
{"update":{"_id":"1"}}
{"doc": { "name": "John Doe becomes Jane Doe" } }
{"delete":{"_id":"2"}}
'
Refer : How to handle multiple updates / deletes with Elasticsearch?
Upvotes: 0
Reputation: 3792
index_name should be as provided as per the index name in your code. Provide the ids to be deleted in the array(1,2,3).
CGI::escape is the URL encoder.
HTTParty.delete "http://#{SERVER_DOMAIN}:9200/index_name/_query?source=#{CGI::escape("{\"terms\":{\"_id\":[1,2,3]}}")}"
This actually uses the delete by query api of elasticsearch.
Upvotes: 1
Reputation: 3792
Incase if you are using tire ruby client to connect to elasticsearch:
id_array = [1,2,3]
query = Tire.search do |search|
search.query { |q| q.terms :_id, id_array }
end
index = Tire.index('<index_name>') # provide the index name as you have in your code
Tire::Configuration.client.delete "#{index.url}/_query?source=#{Tire::Utils.escape(query.to_hash[:query].to_json)}"
Reference: https://github.com/karmi/tire/issues/309
Upvotes: 1