我正在尝试按 ID 进行批量删除,但它似乎不起作用。当我运行我的测试套件并通过 Rails 控制台尝试时,它似乎工作正常。但是,我遇到了一些文档根本没有被删除的情况。然而,响应表明它是成功的。
使用tire
0.5.8、0.8.4、curb
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
模型映射如下所示:
tire.settings ElasticSearchAnalysis do
mapping _all: { enabled: false } do
indexes :id, type: "integer"
end
end
示例 HTTP 删除:
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
未转义时,查询如下所示:
{\"filtered\":{\"query\":{\"match_all\":{}},\"filter\":{\"and\":[{\"terms\":{\"_id\":[587965789,587965791}}]}}}