低版本的es默认post创建索引,指定不了字段类型,在post创建完索引后,mapping是空的,需要在用put创建指定类型
如下
请求方式为put
http://172.16.215.16:9400/bigdata_web_log_new/_mapping/log
{
“logs”: {
“properties”: {
“client_ip”: {
“type”: “string”
},
“code”: {
“type”: “string”
},
“cost_millis”: {
“type”: “string”
},
“message”: {
“type”: “string”
},
“name”: {
“type”: “string”
},
“request_header”: {
“type”: “string”
},
“request_method”: {
“type”: “string”
},
“request_param”: {
“type”: “string”
},
“request_time”: {
“type”: “string”,
“index”:“not_analyzed”
},
“request_url”: {
“type”: “string”
},
“response_code”: {
“type”: “string”
},
“response_header”: {
“type”: “string”
},
“username”: {
“type”: “string”
}
}
},
“log”: {
“properties”: {
“@timestamp”: {
“type”: “date”,
“format”: “strict_date_optional_time||epoch_millis”
},
“@version”: {
“type”: “string”
},
“beat”: {
“properties”: {
“hostname”: {
“type”: “string”
},
“name”: {
“type”: “string”
}
}
},
“count”: {
“type”: “long”
},
“host”: {
“type”: “string”
},
“input_type”: {
“type”: “string”
},
“message”: {
“type”: “string”
},
“offset”: {
“type”: “long”
},
“source”: {
“type”: “string”
},
“tags”: {
“type”: “string”
},
“type”: {
“type”: “string”
}
}
}
}
然后低版本的es,默认都是String类型,没有text和keyword类型,索引默认都是分词的,如果不分词,需要指定type为not_analyzed。
所以系统的时间因为分词了,按时间排序和按时间搜索也就失效了。一开始想的是找时间的逗号问题,但是用没有逗号的时间也是排序无效,以前虽然接触过slor,但是没往这方面想。后来再群里问了一下,说可能是分词。就在postman上测试,排序,
http://172.16.215.16:9400/estest/_search
{
“sort”: { “time”: { “order”: “desc”} },
“from”: 1,
“size”: 20
}
最终发现,sort字段不是完整的时间字段。
最后解决了排序问题。
又面临旧数据导入新的数据的问题,一开始想到了reindex,但是旧版本好像不支持,又看了看说Logstash可以直接指定输出到指定的es下。最后用logstash把旧数据导入完成了