面试题答案
一键面试PUT /ecommerce_products
{
"mappings": {
"properties": {
"name": {
"type": "text",
"analyzer": "ik_max_word"
},
"price": {
"type": "float"
},
"description": {
"type": "text",
"analyzer": "ik_max_word"
},
"category": {
"type": "keyword"
}
}
}
}
上述创建索引 ecommerce_products
的操作中:
name
字段设置为text
类型,使用ik_max_word
分词器,适用于中文分词,以支持商品名称的全文搜索。price
字段设置为float
类型,用于存储商品价格这种浮点数。description
字段设置为text
类型并使用ik_max_word
分词器,方便对商品描述进行全文检索。category
字段设置为keyword
类型,适合进行精确匹配,比如按照商品分类进行筛选。