Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
Deleting ID field from data when sending to ES
Browse files Browse the repository at this point in the history
  • Loading branch information
phutchins committed Jun 1, 2016
1 parent 496a6bb commit 361b4b9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/clientMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const config = require('config');

module.exports = (clientAddress) => {
let thisClient = null;
console.log("config.clients: ", config.clients);
Object.keys(config.clients).forEach((client) => {
if (config.clients[client] === clientAddress || config.clients[client].indexOf(clientAddress) > -1) {
thisClient = client;
Expand Down
2 changes: 1 addition & 1 deletion methods/report/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const log = require('../../lib/logger');

const handleError = (req, res, err) => {
log.warn(`[${req.body.id}] method: ${req.body.method} error: ${err.message} ${err.stack}"`);
log.warn(`[${req.body.id}] method: ${req.body.method} error: ${err.message} ${err.stack}`);
res.status(500).send({
id: req.body.id,
error: 'Error saving report',
Expand Down
9 changes: 6 additions & 3 deletions schemas/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,26 @@ Report.methods.getElasticSearchClient = function getElasticSearchClient() {
Report.methods.createInElasticSearch = function createInElasticSearch(cb) {
const client = this.getElasticSearchClient();
const body = this.toJSON();
log.debug('Creating in ElasticSearch...', body._id);
const id = body._id.toString();
delete body._id;
log.debug('Creating in ElasticSearch...', id);
client.create({
index: 'data-api',
type: 'report',
id: body._id.toString(),
id: id,
body
}, cb);
};

Report.methods.deleteInElasticSearch = function deleteInElasticSearch(cb) {
const client = this.getElasticSearchClient();
const body = this.toJSON();
const id = body._id.toString();
log.debug('Deleting from ElasticSearch...');
client.delete({
index: 'data-api',
type: 'report',
id: body._id.toString()
id: id
}, cb);
};

Expand Down

0 comments on commit 361b4b9

Please sign in to comment.