# 需要注意,新增mapping字段是允许的
# 但是如果是修改,必须删除索引,重新索引
# 即一个字段的类型修改以后,那么该字段的所有数据都需要重新索引
# 创建索引
PUT my_index
# 创建索引mapping
POST my_index/my_child/_mapping
{
"my_ child": {
"_all": {
"enabled": false
},
"properties": {
"source": {
"type": "string"
},
"content": {
"type": "string",
"index": "analyzed",
"analyzer": "ik_max_word"
},
"id": {
"type": "integer"
},
"title": {
"type": "string"
},
"type": {
"type": "string"
},
"create_time": {
"type": "date",
"format":"YYYY-MM-dd HH:mm:ss"
}
}
}
}
# 新增索引mapping
POST my_index/my_child/_mapping
{
"my_child": {
"properties": {
"age":{
"type": "integer"
},
"work_exp":{
"type": "integer"
},
"level1":{
"type": "string",
"index": "analyzed",
"analyzer": "ik_max_word"
},
"level2":{
"type": "string",
"index": "analyzed",
"analyzer": "ik_max_word"
},
"level3":{
"type": "string",
"index": "analyzed",
"analyzer": "ik_max_word"
}
}
}
}
# 查询索引mapping
GET my_index/my_child/_mapping
# 删除索引
DELETE my_index
# 查询内容
GET /my_index/my_child/_search
{
"from": 0,
"size": 10,
"query": {
"bool": {
"must": {
"match": {
"title": "百度"
}
},
"filter": [
{
"range": {
"age": {
"lte": "30"
}
}
},
{
"range": {
"work_exp": {
"gte": "5"
}
}
}
]
}
},
"highlight": {
"fields": {
"title": {}
}
}
}
GET my_index/my_child/_search
{
"query": {
"bool": {
"must": [
{ "match": { "content": "宋建民" }},
{ "match": { "id": "43049" }}
]
}
}
}
GET my_index/my_child/_search
{
"from": 0,
"size": 10,
"query": {
"match": {
"title": "百度"
}
},
"highlight": {
"fields": {
"title": {}
}
}
}
网友评论