Elasticsearch 6.x 新變化
阿新 • • 發佈:2018-11-02
1、Removal of mapping types
雖然一直知道es已經更新到6.x以上,但之前的專案中一直沒有升級,也沒有關注版本更新後有哪些變化。昨天要在新專案中也加入ES,遂直接下載了最新版本的es和logstash,照原先的方法做卻發現出現了新的問題,查閱之後才發現,ES6.0之後版本mapping有了個大變化,它移除了多types的寫法。按照ES的計劃,在之後的版本中,會逐漸淘汰 /index/type/id 中的type這一引數,原因及計劃見文件。
官方文件地址
https://www.elastic.co/guide/en/elasticsearch/reference/6.2/removal-of-types.html
Mapping新寫法
上圖表明6.0後要求一個index只能有一個type,所以現mapping寫法如下:
PUT twitter { "mappings": { "_doc": { "properties": { "type": { "type": "keyword" }, "name": { "type": "text" }, "user_name": { "type": "keyword" }, "email": { "type": "keyword" }, "content": { "type": "text" }, "tweeted_at": { "type": "date" } } } } } #新增 PUT twitter/_doc/user-kimchy { "type": "user", "name": "Shay Banon", "user_name": "kimchy", "email": "
[email protected]" } PUT twitter/_doc/tweet-1 { "type": "tweet", "user_name": "kimchy", "tweeted_at": "2017-10-24T09:00:00Z", "content": "Types are going away" } #查詢 GET twitter/_search { "query": { "bool": { "must": { "match": { "user_name": "kimchy" } }, "filter": { "match": { "type": "tweet" } } } } }
可以看出,它是將原先的單獨的type的欄位取並集放入了一個type中,在put資料時可以指定具體的type,進行區分, 據說這樣可以更好的提交效率。