使用elasticsearch大量api可以如下索引文档:
for doc in shingles:
actions.append({
"_op_type": "index",
"_index": index_name,
'_id': hashed_id,
"content_completion": {
"input": [doc],
"weight": 1
}
})
helpers.bulk(self.es, actions)
但是我需要的是仅对数据建立索引,如果索引中不存在仅doc。如何使用批量API实现此目标?
索引文档时弹性搜索中有一个选项
如果设置op_type = create,它将仅在不存在的情况下创建文档,否则将失败并返回这些文档的错误
POST _bulk/
{ "index" : { "_index" : "test", "_id" : "1" ,**"op_type":"create"** } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_id" : "2" } }
{ "create" : { "_index" : "test", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_id" : "1", "_index" : "test"} }
{ "doc" : {"field2" : "value2"} }
这是相同的链接。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句