-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
95 lines (74 loc) · 3.01 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var client = require('./ElasticMethods');
var _elasticClient = client.getElasticObject();
/**All functions are commented as we dont want you to perform all the query at once.
* just go through them one by one. uncomment the desired function and do some experiment
* with your custom input, and let us know if you found any bug or anything which i have
* not mentioned here.
* Author : Martand Singh
*
* Date : 29 May 2018
*
* Scope : This tutorial will help you to understand how elastic search works with elastic search.
* Elastic search is a wonderfull tool for indexing your data for the fast operation in your
* application. Hope you will like this tutorial
*
* Why this tutorials : As a developer i found it very hard to understand elastic search
* operations as there was no simpler tutorials available. So trying to provide you a simpler
* solutions.
*
* ############ HAPPY INDEXING, Motivate me for the new tutorials ##############
*
* Email : martandsays@gmail.com
*/
//you can check your console for the elastic object structure.
//console.log(_elasticClient);
//this will print the clusture information
//client.checkClustureHealth(_elasticClient);
//creating a index. keep index name in lower case. otherwise you will get an error
//client.createClusture(_elasticClient,'employee');
//Deleting an index
//client.deleteIndex(_elasticClient, 'employee');
var documentData ={
"empcode": "13737",
"empname": "Martand Singh",
"dept": "Tech",
"designation": "Full Stack Developer",
}
var documentDataNew ={
"empcode": "12445",
"empname": "Suman Singh",
"dept": "Network",
"designation": "Network Architect",
}
var documentDataNew1 = {
"empcode": "45344",
"empname": "Ritu Singh",
"dept": "Accounts",
"designation": "Chartered Accountant",
}
//single document insert
//client.createIndex(_elasticClient, 'employee', 'permanent', documentData);
//multiple document insert
// here we can see it will perform bulk operation to index. We can insert, update & delete
// at one go also. in following example we inserted the data at first step with id 23
// then we update its dept to Network administrator on the basis of its id.
// At last we delete the index with id 33
// _elasticClient.bulk({
// body: [
// // action description
// { index: { _index: 'employee', _type: 'permanent', _id: 23 } },
// documentDataNew,
// // action description
// { update: { _index: 'employee', _type: 'permanent', _id: 23 } },
// { doc: { dept: 'Network Administrator' } },
// { delete: { _index: 'employee', _type: 'permanent', _id: 33 } },
// // no document needed for this delete
// ]
// }, function (err, resp) {
// if(resp.errors) {
// console.log(JSON.stringify(resp, null, '\t'));
// }
// });
//client.deleteDocument(_elasticClient, 'employee', 'permanent', 23);
//client.getDocumentCount(_elasticClient, 'employee', 'permanent')
client.searchIndex(_elasticClient, 'employee', 'permanent')