es基本操作
** 索引创建方式**
1.在es客户端kibana中创建
执行即可创建成功
执行代码如下:
PUT /test(索引名称)
{
"mappings": {
"properties": {
"_class": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"category": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart"
},
"id": {
"type": "long"
},
"skuMessage": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart"
},
"title": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart"
}
}
}
}
2.直接通过代码创建索引
pom文件添加es相关依赖
创建对象,对象里面定义数据结构,可以在字段上添加注解,定义字段的分词类型,类上添加@Doucument注解(indexName即为索引名称),项目启动索引自动创建
查看是否创建成功
查看索引结构