自动创建索引功能未开启的状态下,需要首先创建一个索引。
PUT /product_info { "settings": { "number_of_shards": 5, "number_of_replicas": 1 }, "mappings": { "products": { "properties": { "productName": { "type": "text", "analyzer": "ik_smart" }, "productType":{ "type":"keyword" }, "describe": { "type": "text", "analyzer": "ik_smart" } } } } }
PUT /product_info { "settings": { "number_of_shards": 5, "number_of_replicas": 1 }, "mappings": { "properties": { "productName": { "type": "text", "analyzer": "ik_smart" }, "productType":{ "type":"keyword" }, "describe": { "type": "text", "analyzer": "ik_smart" } } } }
注意:官方Elasticsearch 7.0及以上版本将移除映射中的type类型定义,之前版本会继续支持。如果在7.0及以上版本中使用了type,会出现"type": "mapper_parsing_exception"的错误提示。详细信息及解决方案,请参见 Removal of mapping types。
索引创建成功后,返回结果如下:
{ "acknowledged" : true, "shards_acknowledged" : true, "index" : "product_info" }
我们的产品专家为您找到最合适的产品/解决⽅案
1v1线上咨询获取售前专业咨询
专业产品顾问,随时随地沟通