今天遇见的的一个问题是:通过elasticsearch建立了索引(myindex),当mongodb对应的集合中增加数据的时候,能在elasticsearch中查询到。但是,当mongodb中删除数据的时候,elasticsearch确没有相应的变动,也就是说数据没有达到同步。
首先看下我开始创索引的命令:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 |
curl -XPUT "http://localhost:9200/_river/mongodb/_meta" -d'
{
"type":"mongodb",
"mongodb":{
"host":"192.168.100.103",
"port":10111,
"db":"mydb",
"collection":"users",
"options":{
"include_fileds":["_id","is_show","start_time"]
}
},
"index":{
"name":"myindex",
"type":"users"
}
}'
后来才发现是因为
options选中中少配置了参数,修改命令如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 |
curl -XPUT "http://localhost:9200/_river/mongodb/_meta" -d'
{
"type":"mongodb",
"mongodb":{
"servers":{
{"host":"192.168.100.103","port":10111}
},
"options":{
"drop_collection":"users",//当mongodb中的users集何种的数据被删除时,变化同时会反应到elasticsearch上。
"include_fileds":["_id","is_show","start_time"]
},
"db":"mydb",
"collection":"users"
},
"index":{
"name":"myindex",
"type":"users"
}
}'
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 |
curl -XPUT "http://localhost:9200/_river/mongodb/_meta" -d'
{
"type":"mongodb",
"mongodb":{
"servers":{
{"host":"192.168.100.103","port":10111}
},
"options":{
"drop_collection":"users",
"include_fileds":["_id","is_show","start_time"]
},
"db":"mydb",
"collection":"users"
},
"index":{
"name":"myindex",
"type":"users"
}
}'
|