Package: esimport
Tool exists to index content from a CSV in ElasticSearch.UseTo index the contents of a CSV file (where the first row contains field
names) into an ElasticSearch server, you must supply the -s, -f, -i and
-t arguments. If the specified index or type does not exist within the
specified ElasticSearch server, it will be created when the module
executes. The following example will index data from data.file into
ElasticSearch athttp://myserver:9200/myindex/mytype:python-mesimport-smyserver:9200-f/path/to/import/data.file-imyindex-tmytype-sserver(may either be a hostname:port or fully qualified, i.e.
https://servername:port)-ffilepath(location of tab-delimited file to import data from)-iindexname_ (name of the target index within ElasticSearch)-ttypename_ (name of the target document type within
ElasticSearch)Further help available via the script:python-mesimport--helpAdditional OptionsCustom DelimiterThe default delimiter for the operation is a “,”, but you may specify different delimiters via the -d argument.python-mesimport-smyserver:9200-f/path/to/import/data.file-imyindex-tmytype-d'|'-ddelimiter(the delimiter separating columns within the CSV)Clear Existing Data FirstWhen indexing data in ElasticSearch, you may optionally clear the
existing ElasticSearch type before data is added by including the -rm
argument.python-mesimport-smyserver:9200-f/path/to/import/data.file-imyindex-tmytype-rm-rm (removes all documents of given type within the specified index
on ElasticSearch)MappingMapping is the definitiion of the field names and value types of a
document indexed within ElasticSearch. Characteristics such as field
type, whether a field is searchable, and whether to include a timestamp
may all be defined in a map.Please note:If the specified mapping does not match the field names
in the tab-delimited file, you should supply a field translation file
(described below).A mapping file can be specified by adding the -m parameter to the
command:python-mesimport-smyserver:9200-f/path/to/import/data.file-imyindex-tmytype-m/path/to/mapping.json-mmappingfilepath_ (location of JSON formatted mapping file for
specified type)Maps should be provided in JSON format, as seen below and on the
ElasticSearch website.Sample mapping for a document type “tracks”{"tracks":{"properties":{"genre":{"type":"string"},"album":{"type":"string"},"ISRC":{"type":"string"},"recordCompany":{"type":"string"},"artist":{"type":"string"},"songToken":{"type":"integer"},"durationInSeconds":{"type":"integer"},"title":{"type":"string"}}}}More details on mapping may be found inElasticSearch’s mapping
reference.Field TranslationsIf the original field names from the CSV file need to be altered or
filtered during the import, you may provide a field translations file.
The first row of this file should consist of the original field names,
separated by the specified delimiter; the second, the new names, again
separated by the specified delimeter.Please note:Any original field names omitted from the first row, will
be omitted from the indexed data as well. This is a handy way to filter
the columns at time of indexing if that is necessary.python-mesimport-smyserver:9200-f/path/to/import/data.file-imyindex-tmytype-rm-m/path/to/mapping.json-n/path/to/field/name/translations.file-nfieldtranslation_filepath_ (location of CSV field
translation file for specified type)Sample Field Name Translations FileAlbum_Category,Album_ID,ISRC,Record_Co,Song_Artist,Song_ID,Song_Secs,Song_Title
genre,albumID,ISRC,recordCompany,artist,songID,duration,titleBasic AuthIf login credentials are required, add the arguments -user and -passpython-mesimport-shttps://myserver.com-f/path/to/import/data.file-imyindex-tmytype-userexampleuser-passexamplepasswordVerify SSLIf ElasticSearch requires SSL, the -nv setting can be used to bypass certificate verification if necessary.python-mesimport-shttps://myserver.com-f/path/to/import/data.file-imyindex-tmytype-userexampleuser-passexamplepassword-nvBulk Index CountYou may specify the max number of records to index at time (defaults to 1000) by using the-bcargument.python-mesimport-shttps://myserver.com-f/path/to/import/data.file-imyindex-tmytype-userexampleuser-passexamplepassword-bc500TimeoutYou may specify the timeout (defaults to 60) for communication with Elasticsearch using the-Targument..python-mesimport-shttps://myserver.com-f/path/to/import/data.file-imyindex-tmytype-userexampleuser-passexamplepassword-T30DependenciesPython librariesrawes:Github|documentationElasticSearch