2024-04-29 01:27:17 发布
网友
假设我有一些文档,我用下面的python代码将它们放在elasticsearch索引上
es.index(index=index_name, doc_type='_doc', body=doc)
如果我运行两次代码,相同的2个文档将出现在这个elasticsearch索引上。 如何消除同一索引上的重复文档? 谢谢你的回答
您可以设置?op_type=create参数,仅当不存在具有该ID的文档时,才为文档编制索引。例如:
请求1
PUT /customers/_doc/1?op_type=create { "name": "Jane Doe" }
响应1
{ "_index" : "customers", "_type" : "_doc", "_id" : "1", "_version" : 1, "result" : "created", "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 0, "_primary_term" : 1 }
请求2
响应2
{ "error" : { "root_cause" : [ { "type" : "version_conflict_engine_exception", "reason" : "[1]: version conflict, document already exists (current version [1])", "index_uuid" : "5Oar4GFhQjq_EM88qqd6PA", "shard" : "0", "index" : "customers" } ], "type" : "version_conflict_engine_exception", "reason" : "[1]: version conflict, document already exists (current version [1])", "index_uuid" : "5Oar4GFhQjq_EM88qqd6PA", "shard" : "0", "index" : "customers" }, "status" : 409 }
您可以设置?op_type=create参数,仅当不存在具有该ID的文档时,才为文档编制索引。例如:
请求1
响应1
请求2
响应2
相关问题 更多 >
编程相关推荐