首页 > 解决方案 > elasticsearch(6.0.1)中是否有替代方法代替嵌套类型

问题描述

我们在我的索引中嵌套了类型映射,一个索引中有大约 400 万个文档。下面是带有示例的映射。使用 Elasticsearch 6.0.1

"mappings": {
  "inventory": {
      "name" : {
        "type" : "text"
      },
      "id" : {
        "type" : "integer"
      },
      "product_sizes" : {
        "type" : "nested",
        "properties" : {
          "deleted_at" : {
            "type" : "date"
          },
          "ean_code" : {
            "type" : "keyword"
          },
          "id" : {
            "type" : "integer"
          },
          "in_stock" : {
            "type" : "boolean"
          },
          "is_deleted" : {
            "type" : "boolean"
          },
          "price" : {
            "type" : "float"
          },
          "product_id" : {
            "type" : "long"
          },
          "uom" : {
            "type" : "keyword"
          },
          "weight" : {
            "type" : "float"
          }
        }
      }
}

例子

{
 "_index" : "inventory_553",
 "_type" : "inventory",
 "_id" : "16968",
 "_score" : 1.0,
 "_source" : {
   "id" : 16968,
    "name" : "By Nature Quinoa",
    "product_sizes" : [
        {
          "id" : 14991,
          "product_id" : 16968,
          "ean_code" : "RBSDC8909",
          "uom" : "gm",
          "weight" : 500.0,
          "price" : 460.0,
          "is_deleted" : true,
          "deleted_at" : "2019-12-03T15:26:29.854+05:30",
          "in_stock" : true
        },
        {
          "id" : 14990,
          "product_id" : 16968,
          "ean_code" : "TETYC8900",
          "uom" : "gm",
          "weight" : 250.0,
          "price" : 230.0,
          "is_deleted" : true,
          "deleted_at" : "2019-12-03T15:26:29.855+05:30",
          "in_stock" : true
        }
      ]
    }
 }

目前,按价格排序产品,按价格范围查询产品尺寸,in_stock为true,is_deleted为false。有没有其他方法可以进行映射而不是嵌套类型,因为它在查询和更新嵌套文档索引时会影响性能。

标签: elasticsearchelasticsearch-rails

解决方案


推荐阅读