elasticsearch - Elasticsearch 批量操作:如果不存在则插入,否则更新或添加嵌套元素
问题描述
在弹性搜索7.11.0
中,我有描述的产品。
{
"_index" : "products",
"_type" : "_doc",
"_id" : "1234567890123",
"_source" : {
"ean" : "1234567890123",
"title" : "Very nice product",
"merchants" : [
{
"id" : 2,
"name" : "example.com",
"product_id" : "22561",
"description" : "Description of the product",
"price" : "4.25",
"url" : "https://example.com/product",
"imageUrl" : "https://example.com/images/product.jpg",
"in_stock" : true
}
]
}
}
我已经通过批量index
操作添加了这个产品。如果存在,它将更新它,如果不存在,它将创建它。
我收到来自多个商家的产品。一种产品可以存在于一个或多个商家中。这就是为什么我有嵌套元素merchants
。
作为操作想要做的事情bulk
如下:
导入运行:
- 产品不存在:
Create a new product with a nested merchant
- 产品存在:
Check if the merchant exists. If not, create a new nested element, otherwise update the nested elements
我可以一个一个地做,但是由于产品的数量,它不是很方便。我正在使用elasticsearch PHP package
.
解决方案
推荐阅读
- nhibernate - NHibernate - 脱水属性值时出错 - 更新实体
- python - SyntaxError:文件 .pyo 中以“\xbd”开头的非 UTF-8 代码
- offset - 无法确定加载以使用来自不同寄存器的偏移量进行注册
- amazon-web-services - 最新 AWS EC2 实例中的环境变量
- c# - NotifyPropertyChanged 和 ContentControl
- javascript - JavaScript 删除 txt 文档中每 3 行的文本
- angular-material - 我应该如何将数据从我的服务传递到小吃店组件?
- java - Find which url was used to access the controller when multiple url mapping to the same controller method
- c++ - char vs. wchar_t vs. char16_t vs. char32_t
- rest-assured - 放心 - 响应正文验证