6.7. 创建商品索引

本教程最新版为 8.x,当前版本已放弃维护,请阅读最新版本!

创建商品索引

上一节我们学习了 Elasticsearch 类库在 Laravel 项目中的基础使用方法,接下来我们创建一个新的 Elasticsearch 索引用以存放商品数据,以供之后的搜索使用。

1. 创建索引

现在我们需要重新创建一个 Elasticsearch 索引用于保存商品数据,名为 products

$ curl -XPUT http://localhost:9200/products?pretty

接下来定义商品字段:

$ curl -H'Content-Type: application/json' -XPUT http://localhost:9200/products/_mapping/_doc?pretty -d'{
  "properties": {
    "type": { "type": "keyword" } ,
    "title": { "type": "text", "analyzer": "ik_smart" }, 
    "long_title": { "type": "text", "analyzer": "ik_smart" }, 
    "category_id": { "type": "integer" },
    "category": { "type": "keyword" },
    "category_path": { "type": "keyword" },
    "description": { "type": "text", "analyzer": "ik_smart" },
    "price": { "type": "scaled_float", "scaling_factor": 100 },
    "on_sale": {...

本文章首发在 LearnKu.com 网站上。

为了保证课程的高品质,我们需要对课程进行收费。付费后 才能观看剩余内容。 购买

上一篇 下一篇
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
贡献者:1
讨论数量: 7

holashatu
这个_version 字段有什么意义么
1 个点赞 | 1 个回复 | 问答 | 课程版本 5.5
AMA32
求教大佬 Windows+Homestead 如何使用 Kibana?
0 个点赞 | 4 个回复 | 问答 | 课程版本 5.5
AmberLavigne
strip_tags 函数 引起 商品描述 description 的 img 标签也被删除
0 个点赞 | 3 个回复 | 问答 | 课程版本 5.5
KunHong
创建商品索引
0 个点赞 | 1 个回复 | 问答 | 课程版本 7.x
KunHong
创建商品索引
0 个点赞 | 1 个回复 | 问答 | 课程版本 7.x