一擦盾、mapping介紹
"""
mapping,類似于mysql的建表
"""
1淌哟、查看表結(jié)構(gòu)
GET goods/fruit/_mapping
2迹卢、建立表結(jié)構(gòu)
PUT my_index1
{
"mappings": {
# 類型
"doc": {
# 是否為動態(tài)
"dynamic": false,
# 屬性
"properties": {
"name": {"type": text},
"age": {"type": long}
}
}
}
}
二、dynamic關(guān)鍵字
"""
若dynamic=false徒仓,不用指定腐碱,可以隨時插入動態(tài)屬性;但是不會通過動態(tài)的屬性進(jìn)行查詢
若dynamic=true掉弛,不用指定症见,可以隨時插入動態(tài)屬性;會為所有的屬性創(chuàng)建索引
若dynamic=strict殃饿,必須添加指定的屬性谋作;添加動態(tài)的屬性時,會報錯
"""
PUT my_Index1/doc/1
{
"name": "zqx",
"age": 18
}
PUT my_Index1/doc/1
{
"name": "zzz",
"age": 21,
"school": "qinghua"
}
GET my_Index1/doc/1
{
"query": {
"match": {
"school": "qinghua"
}
}
}
三乎芳、copy_to關(guān)鍵字
"""
copy_to參數(shù):把當(dāng)前的值復(fù)制給指定的字段遵蚜;所有的copy_to的值和對copy_to屬性賦的值都可以保留
"""
PUT my_index2
{
"mappings": {
"doc": {
"dynamic": false,
"properties": {
"first_name": {
"type": "text",
"copy_to": "full_name"
},
"last_name": {
"type": "text",
"copy_to": "full_name"
},
"full_name": {
"type": "text"
}
}
}
}
}
PUT my_index2/doc/1
{
"first_name": "kitty",
"last_name": "tomcat"
}
PUT my_index2/doc/2
{
"first_name": "kitty",
"last_name": "python"
}
PUT my_index2/doc/3
{
"first_name": "kitty",
"last_name": "php",
"full_name": "haha"
}
GET my_index2/doc/3
{
"full_name": "kitty" # 有Kitty的3組/代替了first_name
或"full_name": "python" # 有python的1組/代替了last_name
或"full_name": "haha" # 有haha的1組/haha只有full_name有,無法代替
}
三奈惑、index關(guān)鍵字
"""
index屬性谬晕,默認(rèn)為true;如果設(shè)置為false携取,則當(dāng)前屬性不能被創(chuàng)建索引
"""
PUT my_index3/doc/4
{
"mappings": {
"doc": {
"dynamic": false
"properties": {
"name": {
"type": "text",
"index": true
},
"add": {
"type": "text",
"index": false
}
}
}
}
}
PUT my_index3/doc/4
{
"name": "kitty",
"add": "beijing"
}
GET my_index3/doc/4
{
"query": {
"match": {
"add": "beijing" //報錯
}
}
}
四攒钳、對象型屬性
"""
對象型屬性訪問方式為:.進(jìn)入下一級對象屬性
"""
PUT my_Index4/doc/1
{
"name": "tom",
"age": 18,
"add": {
"address": "beijing",
"tel": "18088888888"
}
}
PUT my_Index4/doc/1
{
"name": "zqx",
"age": 21,
"add": {
"address": "beijing",
"tel": "18066666666"
}
}
GET my_Index4/_search
{
"query": {
"match": {
"add.address": "beijing"
}
}
}