Multi-fields Reindex
1. 先獲取索引
get http://192.168.1.51:9200/xxd/_mapping/p1
得到一個JSON,修改這個JSON
官方文檔地址:
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html
2. 修改索引
官網的例子:
PUT my_index
{
"mappings": {
"my_type": {
"properties": {
"city": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
}
}
}
}
}
如果直接照上面的改會報錯:no handler for type [keyword] declared on field [raw]
keyword是ES 5中的一個新類型,ES 2.X不支持
這里實際上修改為:
"currentCompany": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"headline": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"industry": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"location": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
刪掉第一級別的==xxd== 球订,保留如下:
{
"mappings": {
"p1": {
......
3. 添加新的類型到索引中
根據上面修改的JSON創(chuàng)建一個新的類型
put http://192.168.1.51:9200/xxd2
{
"mappings": {
"p1": {
"properties": {
......
官方文檔地址:
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html
4. 通過get驗證新創(chuàng)建的索引
get http://192.168.1.51:9200/xxd2/_mapping/p1
5. Reindex API
官網地址:
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html#docs-reindex
reindex API是新的篇恒,應該仍然被認為是實驗性的。 API可能以不向后兼容的方式更改解虱。
重建索引不會嘗試設置目標索引。它不復制源索引的設置。您應該在運行_reindex操作之前設置目標索引瓶蚂,包括設置映射征候,分片計數现拒,副本等岂丘。
POST http://192.168.1.51:9200/_reindex
{
"source": {
"index": "xxd"
},
"dest": {
"index": "xxd2"
}
}
6. 測試
POST http://192.168.1.51:9200/xxd2/p1/_search?search_type=count
{
"aggs": {
"colors": {
"terms": {
"field": "location.raw"
}
}
}
}