Skip to content
This repository was archived by the owner on Jan 18, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions drivers/csv.driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class CSV extends Driver {
this.id = 'csv';
this.indexCounter = 0;
this.propertyMap = {};
this.header = '';
}

getInfo(callback) {
Expand Down Expand Up @@ -119,10 +120,12 @@ class CSV extends Driver {
}

}
this.header = header;
if (!env.options.target.noheader) {
if (!fs.existsSync(env.options.target.file) || fs.statSync(env.options.target.file).size === 0) {
fs.writeFileSync(env.options.target.file, header + '\n', {encoding: 'utf8'});
}

}
callback();
}
Expand All @@ -135,6 +138,16 @@ class CSV extends Driver {
for (let doc of docs) {
let line = [this.propertyMap.length];
for (let property in doc._source) {
if (!this.propertyMap[property]) {
this.propertyMap[property] = this.indexCounter++;
let separator = env.options.target.separator;
let newHeader = this.header + separator + this._escape(env, property);
let oldHeader = this.header + "";
this.header = newHeader + '';
var data = fs.readFileSync(env.options.target.file, 'utf8');
var result = data.replace(oldHeader, newHeader);
fs.writeFileSync(env.options.target.file, result, 'utf8')
}
line[this.propertyMap[property]] = this._escape(env, doc._source[property]);
}
line.unshift(doc._type);
Expand Down
12 changes: 6 additions & 6 deletions drivers/elasticsearch.driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,25 +400,25 @@ class Elasticsearch extends Driver {
}

_getQuery(env) {
let fields = [ '_source', '_timestamp', '_version', '_routing', '_percolate', '_parent', '_ttl' ];
let stored_fields = [ '_source', '_timestamp', '_version', '_routing', '_percolate', '_parent', '_ttl' ];
let size = env.options.source.size;
let query = env.options.source.query;
if (env.options.source.index) {
let indices = env.options.source.index.split(',');
let indexQuery = { indices: { indices, query, no_match_query: 'none' }};
if (env.options.source.type) {
if (env.statistics.source.version.lt(2.0)) {
return { fields, size, query: indexQuery, filter: { type: { value: env.options.source.type }} };
return { stored_fields, size, query: indexQuery, filter: { type: { value: env.options.source.type }} };
}
let payload = { fields, size, query: { bool: { must: [ indexQuery], should: [], minimum_should_match: 1}}};
let payload = { stored_fields, size, query: { bool: { must: [ indexQuery], should: [], minimum_should_match: 1}}};
for (let type of env.options.source.type.split(',')) {
payload.query.bool.should.push({ type: { value: type }});
}
return payload;
}
return { fields, size, query: indexQuery};
return { stored_fields, size, query: indexQuery};
}
return { fields, size, query };
return { stored_fields, size, query };
}

/**
Expand All @@ -442,7 +442,7 @@ class Elasticsearch extends Driver {
callback(null, data.hits ? data.hits.hits : []);
});
} else {
request.source.post(env, '/_search?search_type=scan&scroll=60m', query, (err, data) => {
request.source.post(env, '/_search?scroll=60m', query, (err, data) => {
if (err) {
return callback(err);
}
Expand Down
Loading