首页 > 解决方案 > 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如下:

导入运行:

我可以一个一个地做,但是由于产品的数量,它不是很方便。我正在使用elasticsearch PHP package.

标签: elasticsearchelasticsearch-bulk-apielasticsearch-php

解决方案


推荐阅读