-
Notifications
You must be signed in to change notification settings - Fork 534
Add "delete by query" support #309
Comments
Hello @karmi, any plans on supporting delete by query? If there is, I can work on the implementation and submit a pull request. Cheers! |
Any word on this? Need to remove items from the search index that have been soft-deleted via ActsAsParanoid. Would like to stay withing the Tire API if posssible, something like |
@thoughtpunch simple use cases can be handled like this:
|
Notice it's easy to use Tire's API/DSL for manually invoking the "Delete by Query" API, until there's a proper support: # Dangerous code removed See the code below |
In order to setup my tests, I want to delete all documents across al indexes, I tried using this:
But I can't search anymore. Does this delete indexes somehow? |
Well, now I am using something simpler:
My problem was the async nature of the setup, so now I am calling refresh() after save and destroy. |
@karmi any news on this now? |
@karmi could you please explain why index gets deleted on "manually invoking the "Delete by Query" API"? (see comment above - #309 (comment)) |
@jurgens @karmi's example is constructing a |
@ches thank you |
@jurgens @Will-Sommers @thoughtpunch Sorry, the advice I gave was incorrect and dangerous (@ches above is right), I apologize. This would be the workaround for the moment: require 'tire'
index = Tire::Index.new('articles')
index = Tire::Index.new('articles') do
delete
store title: 'x'
store title: 'y'
store title: 'z'
refresh
end
query = Tire::Search::Search.new do
query { term :title, 'x' }
end
p query.to_hash
puts query.to_curl
puts "curl '#{index.url}/_search?source=#{Tire::Utils.escape(query.to_hash.to_json)}'"
puts "curl -X DELETE '#{index.url}/_query?source=#{Tire::Utils.escape(query.to_hash[:query].to_json)}'"
p Tire::Configuration.client.delete "#{index.url}/_query?source=#{Tire::Utils.escape(query.to_hash[:query].to_json)}" NOTE: Eg. the |
Thank you @karmi that was helpful! |
is this similar to #771? |
@phoet Yes -- we could support |
@karmi would you consider this a "hack"? and prefer the extension to RestClient for DELETE with payload? |
@phoet I think that would qualify as an "acceptable" hack :) (Of course provided we have unit+integration tests, etc) |
I believe 55d12c0 closed this. |
@karmi I recommend deleting your post way up above if it's dangerous. Someone in a rush might just execute what you suggested w/o scrolling down below. |
There are a couple of fixes to make this work, mainly the curl logging on failure and the json for query on |
Tire doesn't currently support this feature: http://www.elasticsearch.org/guide/reference/api/delete-by-query.html
I hacked together the following solution (we're using it in production). Unfortunately I won't have time to work on this further.
https://gist.github.com/2346772
The text was updated successfully, but these errors were encountered: