0

We have nested type mapping in my index which has around 4 million documents in one index. Below is the mapping with example. Using 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"
          }
        }
      }
}

Example

{
 "_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
        }
      ]
    }
 }

Currently, sorting the products by price, querying product sizes by price range, in_stock is true, and is_deleted is false. Is there any other way by which we can do mapping instead of nested type as it is impacting the performance while querying & updating the nested document index.

Beena Shetty
  • 3,676
  • 2
  • 28
  • 31
  • 1
    I would definitely denormalize. See this thread: https://stackoverflow.com/questions/30616549/associated-data-in-elasticsearch/30616853#30616853 – Val Jun 08 '20 at 14:14
  • Thanks for the answer. After denormalize how we get a list of all the products with its product_sizes in it with pagination. – Beena Shetty Jun 08 '20 at 14:44
  • You can leverage [field collapsing](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#request-body-search-collapse) for that purpose. – Val Jun 08 '20 at 14:45
  • Thanks. I will look into it. – Beena Shetty Jun 08 '20 at 14:47
  • We are using version 6.0 and don't think so field collapsing is available for this version. – Beena Shetty Jun 08 '20 at 14:52
  • 2
    Sure, it was already available at that time: https://www.elastic.co/guide/en/elasticsearch/reference/6.0/search-request-collapse.html – Val Jun 08 '20 at 14:53
  • Were you able to solve I have a similar use -case I have a list of locations against a coupon object and I wan't to show x number of coupons with nearest applicable store with each coupon – Aadi May 04 '21 at 08:48

0 Answers0