ductile
v1.5.0
Published
Elasticsearch Bulk Loader
Downloads
45
Maintainers
Readme
ductile
Elasticsearch Bulk Loader for quick export/import of bulk formatted data.
Install
$ npm install -g ductile
Usage
Export
$ ./ductile export --help
Usage: ductile export [options] <url>
Options:
--help Show help [boolean]
-d, --delete output delete operations [boolean] [default: false]
-q, --query file with json query [string]
-t, --transform file with transform function [string]
Export with Index/Type in the URL
The data to export is narrow by specifying the index, and optionally the type in the URL.
Alias
The exported bulk items always retain their original index name even if exported using an index alias in the URL. To alter the index (or type, you must use a transform.
Import
$ ./ductile import --help
Usage: ductile import [options] <url>
Options:
--help Show help [boolean]
-d, --delete change incoming index operations to delete [boolean] [default: false]
-t, --transform file with transform function [string]
Import with Index/Type in the URL
When importing, an index or alias in the URL will override that in the bulk data.
Alias
Exports (non standard) alias bulk operations.
$ ./ductile alias --help
Usage: ductile alias <url>
Options:
--help Show help [boolean]
Examples
This tools works with stdin/stdout.
Export
$ ductile export http://elastichost:9200/myindex
{"index":{"_index":"myindex","_type":"mytype","_id":"sdltb459b78"}}
{"type":"picture","mimetype":"image/jpeg","representationtype":"complete","pubstatus":"usable","copyrightholder":"Afp","product":[{"code":"FOAFP","nam
...
To file
$ ductile export http://elastichost:9200/myindex > dump.bulk
With type
$ ductile export http://elastichost:9200/myindex/mytype > dump.bulk
To delete operations
$ ./ductile export -d http://devbox.local:9200/myindex
{"delete":{"_index":"myindex","_type":"mytype","_id":"sdltb459b78"}}
{"delete":{"_index":"myindex","_type":"mytype","_id":"sdltb45b7ad"}}
{"delete":{"_index":"myindex","_type":"mytype","_id":"sdltb45b7cc"}}
{"delete":{"_index":"myindex","_type":"mytype","_id":"sdltb45be86"}}
With a query
Queries are JSON formatted elasticsearch queries. The default query is a match_all
.
The query file is require
, so it can also be expressed as .js
or '.json'
$ ./ductile export -q ./query.json http://devbox.local:9200/dist-sdl-20160314
{"index":{"_index":"myindex","_type":"mytype","_id":"sdltb459b78"}}
{"type":"picture","mimetype":"image/jpeg","representationtype":"complete","pubstatus":"usable","copyrightholder":"Afp","product":[{"code":"FOAFP","nam
The query.json
:
{
"query": {
"match_all": {}
}
}
Transform output
Output can optionally be transformed before turned into bulk.
The transform file is require
, and must produce a function.
$ ductile export -t ./mytransform.js http://elastichost:9200/myindex/mytype > dump.bulk
The mytransform.js
:
module.exports = function(hit) {
hit._source.changedvalue = "PANDA!";
return hit;
};
The function must return the item. Returning nothing or null
will
drop the item, and can be used as a programmatic filter.
The input to the function is a hit as produced by elasticsearch. Any part of the input can be changd.
{
"_index": "myindex",
"_type": "mytype",
"_id": "sdltb459b78",
"_score": 1,
"_source": { }
}
Import
From an export
$ ductile export http://host1:9200/myindex1 | ductile import http://host2:9200/myindex2
From a file
$ ductile import http://elastichost:9200/myindex < dump.bulk
Make delete operations
Index operations can be turned to delete operations.
$ ductile import -d http://elastichost:9200/myindex < dump-with-index-oper.bulk
Transform input
Input can be optionally transformed.
The transform file is require
, and must produce a function.
$ ductile import -t ./mytransform.js http://elastichost:9200/myindex/mytype < dump.bulk
The mytransform.js
:
module.exports = function(hit) {
hit._source.changedvalue = "PANDA!";
return hit;
};
The function must return the item. Returning nothing or null
will
drop the item, and can be used as a programmatic filter.
Even though the input is a bulk format, the the input to the function is a synthetic hit similar to that produced by elasticsearch searches. Any part of the input can be changd.
Worth noting is the non-elasticsearch-standard _oper
field that
will hold one of index
, create
, delete
or update
.
{
"_index": "myindex",
"_type": "mytype",
"_id": "sdltb459b78",
"_score": 1,
"_oper": "index",
"_source": { }
}
Alias
$ ./ductile alias http://elast01:9200/dist-sdl | $ ./ductile import http://elast02:9200/dist-sdl
License
The MIT License (MIT)
Copyright © 2016 Martin Algesten
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Some code was borrowed/changed from elasticsearch-streams which is Copyright (c) 2015 Sutoiku, Inc.