数据库中可以对表的字段、长度、类型做限制,ES中通过映射配置。
先创建一个students2的索引:http://127.0.0.1:9200/students2
在通过mapping设置文档属性:http://127.0.0.1:9200/students2/_mapping
请求body内容为:
{
"properties": {
"姓名": {
"type": "keyword", // keyword不分词,还可以设置为text(会进行分词)
"index": true // 是否可以索引查询,false表示不可以作为查询条件进行查询
},
"年级": {
"type": "keyword",
"index": true
},
"班级": {
"type": "keyword",
"index": true
},
"个人介绍": {
"type": "text",
"index": false
}
}
}
设置成功后,也可以通过get操作查询: