0

这是我的代码:

HTTParty.delete("http://#{SERVER_DOMAIN}:9200/monitoring/mention_reports/_query?q=id:11321779,11321779", { 
    })

我想使用 id 批量删除数据,但此查询没有从 elasticsearch 中删除数据

谁能帮我弄清楚如何批量删除数据?

4

3 回答 3

1

index_name 应根据代码中的索引名称提供。提供要在数组 (1,2,3) 中删除的 id。

CGI::escape 是 URL 编码器。

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

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

于 2013-09-04T10:31:38.163 回答
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)}"

参考:https ://github.com/karmi/tire/issues/309

于 2013-09-04T10:35:23.460 回答
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"} }

或者

curl -XPOST 'localhost:9200/customer/external/_bulk?pretty' -d '
{"update":{"_id":"1"}}
{"doc": { "name": "John Doe becomes Jane Doe" } }
{"delete":{"_id":"2"}}
'

参考:如何使用 Elasticsearch 处理多个更新/删除?

于 2015-09-29T08:28:48.133 回答