elasticsearch,Ruby On Rails,Ruby,elasticsearch" /> elasticsearch,Ruby On Rails,Ruby,elasticsearch" />

Ruby on rails elasticsearch中的批量数据删除

Ruby on rails elasticsearch中的批量数据删除,ruby-on-rails,ruby,elasticsearch,Ruby On Rails,Ruby,elasticsearch,这是我的代码: HTTParty.delete("http://#{SERVER_DOMAIN}:9200/monitoring/mention_reports/_query?q=id:11321779,11321779", { }) 我想使用id批量删除数据,但此查询不是从elasticsearch中删除数据 有人能帮我弄清楚如何批量删除数据吗?索引名称应按照代码中的索引名称提供。在数组中提供要删除的ID(1,2,3) escape是URL编码器 HTTParty.delete "

这是我的代码:

HTTParty.delete("http://#{SERVER_DOMAIN}:9200/monitoring/mention_reports/_query?q=id:11321779,11321779", { 
    })
我想使用id批量删除数据,但此查询不是从elasticsearch中删除数据


有人能帮我弄清楚如何批量删除数据吗?

索引名称应按照代码中的索引名称提供。在数组中提供要删除的ID(1,2,3)

escape是URL编码器

HTTParty.delete "http://#{SERVER_DOMAIN}:9200/index_name/_query?source=#{CGI::escape("{\"terms\":{\"_id\":[1,2,3]}}")}"

这实际上使用了elasticsearch的delete by query api。

如果您使用tire 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)}"
id_数组=[1,2,3]
query=Tire.search do | search|
search.query{| q | q.terms:_id,id_array}
结束
index=Tire.index(“”)#提供代码中的索引名称
Tire::Configuration.client.delete“#{index.url}/_query?source=#{Tire::Utils.escape(query.to_hash[:query].to_json)}”

参考:

提供的规定使用:


请参阅:

您使用哪个ruby客户端连接到elasticsearch?
{ "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"} }
curl -XPOST 'localhost:9200/customer/external/_bulk?pretty' -d '
{"update":{"_id":"1"}}
{"doc": { "name": "John Doe becomes Jane Doe" } }
{"delete":{"_id":"2"}}
'