ElasticSearch Bulk Remove by ID

I am trying to do a bulk deletion using ids and does not seem to work. When I run my test suite and try through the Rails console, it works fine. However, I come across cases when there are documents that simply cannot be deleted. However, the answer indicates that it was successful.

Using tire 0.5.8, curb 0.8.4, ElasticSearch 0.90.2.

 query = Tire::Search::Search.new do query do filtered do query { all } filter(:terms, _id: ids_array) end end end Curl::Easy.http_delete("#{index.url}/_query?source=#{Tire::Utils.escape(query.to_hash[:query].to_json)}") do |curb| curb.http_auth_types = :basic curb.username = ENV["ELASTICSEARCH_USERNAME"] curb.password = ENV["ELASTICSEARCH_PASSWORD"] end 

The model display is as follows:

 tire.settings ElasticSearchAnalysis do mapping _all: { enabled: false } do indexes :id, type: "integer" end end 

HTTP DELETE example:

 DELETE /production_shifts/_query?source=%7B%22filtered%22%3A%7B%22query%22%3A%7B%22match_all%22%3A%7B%7D%7D%2C%22filter%22%3A%7B%22and%22%3A%5B%7B%22terms%22%3A%7B%22_id%22%3A%5B587965789%2C587965791%7D%7D%5D%7D%7D%7D 

If the request fails, the request looks like this:

 {\"filtered\":{\"query\":{\"match_all\":{}},\"filter\":{\"and\":[{\"terms\":{\"_id\":[587965789,587965791}}]}}} 
+4
source share
2 answers

That the "and" in the json request does not look right. Nothing will match this query.

In any case, try the same query to find out that you are coming back.

0
source

Why do you need a filtered query?

You specified the id field as id not _id ... The next request should work exactly, this is a verified request.

You can just use this,

 query = Tire.search do |search| search.query { |q| q.terms :id, ids_array } end 

Link: https://github.com/karmi/tire/issues/309

0
source

Source: https://habr.com/ru/post/1490775/


All Articles