不知不觉要写第二篇文章了
接着第一篇文章,es实现like复合查询,里面案例有用到通过时间(年-月-日 时:分:秒)进行筛选的,
在这里说下如果通过时间筛选需要对index进行mapping设置滴,不然不行的
首先,创建一个索引index
PUT /index
好勒,创建好索引了,接下来开始对索引进行mapping设置,相当于定义数据库表字段,不过不用担心设置了多余的mapping字段,没关系的,索引下面的type会去自动匹配mapping对应的设置的, 如果没匹配到es会默认根据值去分配的
接下来老习惯,直接上案例mapping
操作:
PUT /index/_mapping
mapping时提交的body内容如下
{
"index":{
"mappings":{
"_default_":{
"_source":{
"enabled":true
},
"properties":{
"title":{
"type":"string",
"index":"analyzed",
"analyzer":"ik_max_word"
},
"id":{
"type":"integer"
},
"img":{
"type":"string",
"index":"no"
},
"start_time":{
"type":"date",
"format":"yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis",
"ignore_malformed":true
},
"end_time":{
"type":"date",
"format":"yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis",
"ignore_malformed":true
}
}
}
}
}
}
在6.7版本中
PUT /index/_mapping/type_name
mapping
{
"properties":{
"sn":{
"type":"keyword"
},
"ip":{
"type":"keyword"
},
"create_at":{
"type":"date",
"format":"yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis",
"ignore_malformed":true
}
}
}
解说环节
算了,应该不需要解说了,不知道上面如何解说了。。。ㄟ( ▔, ▔ )ㄏ完了