单位现在的搜索系统,每天凌晨,都会做一个全量更新.然后数据一天之内就不会变了...
以后引入准实时搜索之后,为了保险起见,我可能还会保留凌晨的全量更新.
我大致会采用如下方式,
创建两个索引songod_m1和songod_m2,和一个别名 songod
每天凌晨,全量更新备用的索引,完成之后,切换别名.周而复始.
准实时搜索的功能,通过Canal将MySQL的变化,异步更新到ES集群.
这其中肯定有数据不一致的风险.但是我觉得可以接受.
创建模板.
提交模板.
[root@localhost/tmp]$curl -XPUT http://192.168.16.114:9200/_template/songod?pretty --data-binary @index.json
{
"acknowledged" : true
}
初始化数据,并创建别名
[root@localhost/tmp]$curl -XPOST http://192.168.16.114:9200/_aliases -d '
> {
> "actions": [
> {
> "add": {
> "index": "songod_m1",
> "alias": "songod"
> }
> }
> ]
> }
> '
凌晨时候,先查询别名的实际指向。
[root@localhost/tmp]$curl http://192.168.16.114:9200/songod/_aliases?pretty
{
"songod_m1" : {
"aliases" : {
"songod" : { }
}
}
}
然后删除 songod_m2 索引,再重建.
重建完成,更改别名.
[root@localhost/tmp]$curl -XPOST http://192.168.16.114:9200/_aliases -d '
{
"actions": [
{
"remove": {
"index": "songod_m1",
"alias": "songod"
},
"add": {
"index": "songod_m2",
"alias": "songod"
}
}
]
}
'
再次查看别名,已经更改.
[root@localhost/tmp]$curl http://192.168.16.114:9200/songod/_aliases?pretty
{
"songod_m2" : {
"aliases" : {
"songod" : { }
}
}
}
[root@localhost/tmp]$
JAVA应用程序只需要引用 songod别名即可.
以后引入准实时搜索之后,为了保险起见,我可能还会保留凌晨的全量更新.
我大致会采用如下方式,
创建两个索引songod_m1和songod_m2,和一个别名 songod
每天凌晨,全量更新备用的索引,完成之后,切换别名.周而复始.
准实时搜索的功能,通过Canal将MySQL的变化,异步更新到ES集群.
这其中肯定有数据不一致的风险.但是我觉得可以接受.
创建模板.
- {
- "template": "songod*",
- "order": 1,
- "settings": {
- "index": {
- "index.number_of_replicas": 1,
- "number_of_shards": 5,
- "refresh_interval": "30s"
- }
- },
- "mappings": {
- "sod_song_ksc": {
- "dynamic_templates": [
- {
- "all_field": {
- "mapping": {
- "index": "no",
- "store": "yes",
- "type": "{dynamic_type}",
- "include_in_all": false
- },
- "match": "*"
- }
- }
- ],
- "_source": {
- "enabled": false
- },
- "_all": {
- "enabled": true,
- "analyzer": "ik"
- },
- "properties": {
- "SongID": {
- "type": "long",
- "store": "yes",
- "index": "not_analyzed",
- "include_in_all": true
- },
- "Name": {
- "type": "multi_field",
- "fields": {
- "Name": {
- "type": "string",
- "store": "yes",
- "index": "analyzed",
- "analyzer": "ik"
- },
- "raw": {
- "type": "string",
- "store": "yes",
- "index": "not_analyzed",
- "include_in_all": true
- }
- }
- },
- "SingerName": {
- "type": "string",
- "store": "yes",
- "index": "analyzed",
- "analyzer": "stop",
- "include_in_all": true
- }
- }
- }
- }
- }
提交模板.
[root@localhost/tmp]$curl -XPUT http://192.168.16.114:9200/_template/songod?pretty --data-binary @index.json
{
"acknowledged" : true
}
初始化数据,并创建别名
[root@localhost/tmp]$curl -XPOST http://192.168.16.114:9200/_aliases -d '
> {
> "actions": [
> {
> "add": {
> "index": "songod_m1",
> "alias": "songod"
> }
> }
> ]
> }
> '
凌晨时候,先查询别名的实际指向。
[root@localhost/tmp]$curl http://192.168.16.114:9200/songod/_aliases?pretty
{
"songod_m1" : {
"aliases" : {
"songod" : { }
}
}
}
然后删除 songod_m2 索引,再重建.
重建完成,更改别名.
[root@localhost/tmp]$curl -XPOST http://192.168.16.114:9200/_aliases -d '
{
"actions": [
{
"remove": {
"index": "songod_m1",
"alias": "songod"
},
"add": {
"index": "songod_m2",
"alias": "songod"
}
}
]
}
'
再次查看别名,已经更改.
[root@localhost/tmp]$curl http://192.168.16.114:9200/songod/_aliases?pretty
{
"songod_m2" : {
"aliases" : {
"songod" : { }
}
}
}
[root@localhost/tmp]$
JAVA应用程序只需要引用 songod别名即可.
![](http://img.blog.itpub.net/blog/attachment/201605/20/29254281_1463753074pyeG.jpg?x-oss-process=style/bb)
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29254281/viewspace-2104016/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29254281/viewspace-2104016/