/* * Insert document into cluster. */ report(data) { const {client, index, type} = this; // Insert document into cluster. return Promise.fromNode(cb => { client.index({index, type, body: data}, cb); }); }
const insertDoc = async function(indexName, _id, mappingType, data){ return await esClient.index({ index: indexName, type: mappingType, id: _id, body: data }); }
SAMPLES.forEach((sample) => { console.log(`Saving Todo ${sample.todo} to Elasticsearch`); CLIENT.index({ index: INDEX, type: TYPE, id: sample.todo_id, body: sample }, (error, response) => { if(error) { console.log('DOH! Something went wrong!'); } else { console.log(response.result); } }); });
async index(index, type, id, body) { if (parseInt(this.env.ES_MAJOR, 10) > 5) { body.type = type; type = 'doc'; } let exists = false; if (id) { exists = await this.client .exists({ index: index, type: type, id: id }); } if (!exists) { // Only create item if it does not exist return await this.client .index({ index: index, type: type, id: id, body: body }); } return { _id: id, result: 'exists', statusCode: 200, reason: 'Already exists' }; }
function write(buf) { //operations on buffer var obj = JSON.parse(buf.toString()); counter += 1; process.stdout.write('Processed: ' + counter + '\r'); client.index({ index: 'osm', type: 'meta', id: obj.id, body: obj }, function(err, resp) { if (err) { console.error(err) } }) }
async defaultIndex(name) { let id = this.env.ES_VERSION; let body = { defaultIndex: name }; let type = 'config'; if (parseInt(this.env.ES_MAJOR, 10) > 5) { id = 'config:' + this.env.ES_VERSION; type = 'doc'; body = { type: 'config', config: { defaultIndex: name } }; } await this.client .index({ index: (this.env.KB_INDEX || '.kibana'), type: type, id: id, body: body }); this.logElastic('info', `[DEFAULT] Default Index set to [${name}]`); }
client.index({ index: 'store', type: 'mytype', id: json[i].id, body: { storeName: json[i].storeName, location: { lat: json[i].latitude, lon: json[i].longitude } } }, function (error, response) {});
/* data = { index: 'gov', id: '1', type: 'constituencies', body: { "ConstituencyName": "Ipswich", "ConstituencyID": "E14000761", "ConstituencyType": "Borough", "Electorate": 74499, "ValidVotes": 48694, } } */ function insertOne(data) { return createIndex('amazonn').then((resp) => { client.index(data, function(err, resp, status) { console.log(resp._id) }) }) }
const indexDocuments = (docs) => { const promises = docs.map((doc) => { const { id, name } = doc; return client.index({ index, type, id, body: { name }, }); }); return Promise.all(promises); }
async addSite(doc) { return await this.client.index({ index: "site", type: "_doc", body: doc }) }
/* * Insert document into cluster. */ report(data) { const {client, index, type} = this; // Insert document into cluster. return Promise.fromNode(cb => { client.index({index, type, body: data}, cb); }); }