Created
April 9, 2012 21:51
-
-
Save romanbsd/2346772 to your computer and use it in GitHub Desktop.
tire delete_by_query (ElasticSearch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Temporary extension. This will be merged into Tire eventually. | |
module RestClient | |
def self.delete_with_payload(url, payload, headers={}, &block) | |
Request.execute(:method => :delete, :url => url, :payload => payload, :headers => headers, &block) | |
end | |
end | |
module Tire | |
module HTTP | |
module Client | |
class RestClient | |
# Allow data to be passed to delete | |
def self.delete(url, data = nil) | |
if data | |
perform ::RestClient.delete_with_payload(url, data) | |
else | |
perform ::RestClient.delete(url) | |
end | |
rescue *ConnectionExceptions | |
raise | |
rescue ::RestClient::Exception => e | |
Response.new e.http_body, e.http_code | |
end | |
end | |
end | |
end | |
class Index | |
# Removes items which match the query | |
# | |
# @see http://www.elasticsearch.org/guide/reference/api/delete-by-query.html | |
# @example | |
# { | |
# "bool": { | |
# "must": { | |
# "term":{"user_id":1} | |
# }, | |
# "must": { | |
# "terms":{"uid":[12972, 12957, 12954]} | |
# } | |
# } | |
# } | |
def delete_by_query(&blk) | |
raise ArgumentError.new('block not supplied') unless block_given? | |
query = Tire::Search::Query.new(&blk) | |
Configuration.client.delete("#{Configuration.url}/#{@name}/_query", query.to_json) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment