商品上架=将数据添加到ES中和渲染首页和三级分类

本文介绍了如何为谷粒商城的商品创建Elasticsearch索引,用于提高商品检索效率。首先展示了商品的基本字段类型,如skuId、skuTitle和brandName等,并讨论了在实现检索时品牌名字的聚合处理。接着提供了调整后的索引映射,强调了brandImg和brandName的设置,确保它们不可被检索但可用于页面展示。最后提到了首页和三级分类的渲染参考链接,帮助完成整个搜索和展示功能。
摘要由CSDN通过智能技术生成

商品上架之后,多进行几个商品的上架,以便于后期商品检索的时候,能够进行测试

谷粒商城product的Elasticsearch索引

##查询product索引
GET product/_search

##建立product索引
PUT product
{
  "mappings": {
    "properties": {
      "skuId":{
        "type": "long"
      },
      "spuId":{
        "type": "keyword"
      },
     "skuTitle":{
       "type": "text",
       "analyzer": "ik_smart"
     },
     "skuPrice":{
       "type": "keyword"
     },
     "skuImg":{
       "type": "keyword",
       "index": false,
       "doc_values": false
     },
     "saleCount":{
       "type": "long"
     },
     "hasStock":{
       "type": "boolean"
     },
     "hotScore":{
       "type": "long"
     },
     "brandId":{
       "type": "long"
     },
     "catalogId":{
       "type": "long"
     },
     "brandName":{
       "type": "keyword",
       "index": false,
       "doc_values": false
     },
     "brandImg":{
       "type": "keyword",
       "index": false,
       "doc_values": false
     },
     "catalogName":{
       "type": "keyword",
       "index": false,
       "doc_values": false
     },
     "attrs":{
       "type": "nested",
       "properties": {
         "attrId":{
           "type":"long"
         },
         "attrName":{
           "type":"keyword",
           "index": false,
           "doc_values": false
         },
         "attrValue":{
            "type": "keyword"
         }
       }
     }
    }
  }
}

在实现检索的时候,需要品牌名字进行聚合处理,映射应该改成以下的形式

 
PUT gulimall_product
{
  "mappings": {
    "properties": {
      "attrs": {
        "type": "nested",
        "properties": {
          "attrId": {
            "type": "long"
          },
          "attrName": {
            "type": "keyword"
          },
          "attrValue": {
            "type": "keyword"
          }
        }
      },
      "brandId": {
        "type": "long"
      },
      "brandImg": {
        "type": "keyword",
        "index": false,  # 不可被检索,不生成index,只用做页面使用
        "doc_values": false # 不可被聚合,默认为true
      },
      "brandName": {
        "type": "keyword"
      },
      "catalogId": {
        "type": "long"
      },
      "catalogName": {
        "type": "keyword"
      },
      "hasStock": {
        "type": "boolean"
      },
      "hotScore": {
        "type": "long"
      },
      "saleCount": {
        "type": "long"
      },
      "skuId": {
        "type": "long"
      },
      "skuImg": {
        "type": "keyword"
      },
      "skuPrice": {
        "type": "keyword"
      },
      "skuTitle": {
        "type": "text",
        "analyzer": "ik_smart"
      },
      "spuId": {
        "type": "keyword"
      }
    }
  }
}

渲染首页和三级分类

https://blog.csdn.net/pyd1040201698/article/details/108205344

https://blog.csdn.net/pyd1040201698/article/details/108208374

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值