6.7. 创建商品索引
创建商品索引
上一节我们学习了 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": {...