-
Notifications
You must be signed in to change notification settings - Fork 55
ElasticSearch EventBus Operations
田传武 edited this page Jun 19, 2014
·
8 revisions
The elasticsearch index name is realtime. Snapshots are stored in _type=docType. Operations are stored in _type=docType_ops.
For example: if you have an id called users/larry, the snapshot is stored in _type=users with _id=larry, the operations are stored in _type=users_ops with _id=larry_v0, larry_v1, larry_v2 and so on.
Javascript EventBus template
msg = {action: "search"};
log = function(message) {
console.log(JSON.stringify(message.body(), null, 2));
window.message = message;
};
bus.send("realtime/search", msg, log);
msg = {
"action": "get",
"_index": "realtime",
"_type": "users",
"_id": "larry"
};
msg = {
"action": "search",
"_index": "realtime",
"_type": "users_ops",
"source": {
"sort": {"v": {"order": "desc", "ignore_unmapped": true}},
"size": 1,
"filter": {
"term": {"docId": "larry"}
}
}
};
msg = {
"action": "index",
"_index": "realtime",
"_type": "users",
"_id": "larry",
"version_type": "external",
"version": 1,
"source": {
"_snapshot": []
}
};
msg = {
"action": "search",
"_index": "realtime",
"_type": "users_ops",
"source": {
"sort": {"v": {"ignore_unmapped": true}},
"size": 100,
"filter": {
"and": [
{"term": {"docId": "larry"}},
{"range": {"v": {"gte":0, "lt":100}}}
]
}
}
};
msg = {
"action": "index",
"_index": "realtime",
"_type": "users_ops",
"_id": "larry_v0",
"op_type": "create",
"source": {
"docId": "larry",
"_op": [],
"v": 0,
"sid": "sessionId",
"seq": 1,
"uid": "userId"
}
};