创建映射关系
创建mapping
映射类似于我们创建表结构,规定字段什么类型,多长等基本信息。
先创建 索引 PUT
http://127.0.0.1:9200/user
然后创建映射关系
PUT
http://127.0.0.1:9200/user/_mapping
{
"properties":{
"name":{
"type":"text", // text 文本 可以分词
"index":true // 可以索引查询
},
"sex":{
"type":"keyword", // 不可以分词
"index":true
},
"tel":{
"type":"keyword", // 不可以分词
"index":false
}
}
}
更具映射关系创建数据
POST
http://127.0.0.1:9200/user/_doc/1001
{
"name":"小花",
"sex":"男",
"tel":"123456"
}
查询有什么区别呢?
GET
http://127.0.0.1:9200/user/_search
{
"query":{
"match":{
"sex":"男的"
}
}
}
会发现没有查到数据,为什么没有分词呢?因为mapping限制的sex为keyword
GET
http://127.0.0.1:9200/user/_search
{
"query":{
"match":{
"tel":"123456"
}
}
}
报错了!因为他的index是false,没有索引不支持查询