这是我的代码:
HTTParty.delete("http://#{SERVER_DOMAIN}:9200/monitoring/mention_reports/_query?q=id:11321779,11321779", {
})
我想使用id批量删除数据,但此查询不会从elasticsearch
中删除数据任何人都可以帮我弄清楚如何批量删除数据?
答案 0 :(得分:1)
index_name应该按照代码中的索引名称提供。提供要在数组中删除的ID(1,2,3)。
CGI :: escape是URL编码器。
HTTParty.delete "http://#{SERVER_DOMAIN}:9200/index_name/_query?source=#{CGI::escape("{\"terms\":{\"_id\":[1,2,3]}}")}"
这实际上使用了弹性搜索的查询api删除。
答案 1 :(得分:1)
如果您使用轮胎ruby客户端连接到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)}"
答案 2 :(得分:0)
使用以下内容提供规定: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"}}
'
参考:How to handle multiple updates / deletes with Elasticsearch?