# Buggy code
def WriteHeader(self):
    """Setup the Elasticsearch index."""
    if not self._mapping:
        self._mapping = {}

    if self._raw_fields:
        if self._doc_type not in self._mapping:
            self._mapping[self._doc_type] = {}

        _raw_field_mapping = [
            {
                "strings": {
                    "match_mapping_type": "string",
                    "mapping": {
                        "fields": {
                            "raw": {
                                "type": "string",
                                "index": "not_analyzed",
                                "ignore_above": self._ELASTIC_ANALYZER_STRING_LIMIT,
                            }
                        }
                    },
                }
            }
        ]
        self._mapping[self._doc_type]["dynamic_templates"] = _raw_field_mapping

    self._elastic = ElasticSearchHelper(
        self._output_mediator,
        self._host,
        self._port,
        self._flush_interval,
        self._index_name,
        self._mapping,
        self._doc_type,
        self._elastic_user,
        self._elastic_password,
    )
    logging.info("Adding events to Elasticsearch..")


# Traceback (TypeError)
2017-03-27 09:18:34,497 [INFO] (MainProcess) PID:5106 <timesketch_out> Timeline name: test

2017-03-27 09:18:34,497 [INFO] (MainProcess) PID:5106 <timesketch_out> Owner of the timeline: None
Traceback (most recent call last):
File "/usr/local/bin/psort.py", line 4, in <module>
__import__('pkg_resources').run_script('plaso==1.5.2.post20170221', 'psort.py')
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 719, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 1504, in run_script
exec(code, namespace, namespace)
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170221-py2.7.egg/EGG-INFO/scripts/psort.py", line 910, in <module>
if not Main():
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170221-py2.7.egg/EGG-INFO/scripts/psort.py", line 896, in Main
tool.ProcessStorage()
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170221-py2.7.egg/EGG-INFO/scripts/psort.py", line 840, in ProcessStorage
time_slice=self._time_slice, use_time_slicer=self._use_time_slicer)
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170221-py2.7.egg/plaso/frontend/psort.py", line 225, in ExportEvents
use_time_slicer=use_time_slicer)
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170221-py2.7.egg/plaso/multi_processing/psort.py", line 661, in ExportEvents
output_module, deduplicate_events)
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170221-py2.7.egg/plaso/output/event_buffer.py", line 92, in __init__
self._output_module.WriteHeader()
File "/usr/local/lib/python2.7/dist-packages/plaso-1.5.2.post20170221-py2.7.egg/plaso/output/timesketch_out.py", line 158, in WriteHeader
self._index_name, _document_mapping, self._doc_type)
TypeError: __init__() takes exactly 10 arguments (8 given)

# Fixed code
def WriteHeader(self):
    """Setup the Elasticsearch index."""
    if not self._mapping:
        self._mapping = {}

    if self._raw_fields:
        if self._doc_type not in self._mapping:
            self._mapping[self._doc_type] = {}

        _raw_field_mapping = [
            {
                "strings": {
                    "match_mapping_type": "string",
                    "mapping": {
                        "fields": {
                            "raw": {
                                "type": "string",
                                "index": "not_analyzed",
                                "ignore_above": self._ELASTIC_ANALYZER_STRING_LIMIT,
                            }
                        }
                    },
                }
            }
        ]
        self._mapping[self._doc_type]["dynamic_templates"] = _raw_field_mapping

    self._elastic = ElasticSearchHelper(
        self._output_mediator,
        self._host,
        self._port,
        self._flush_interval,
        self._index_name,
        self._mapping,
        self._doc_type,
        elastic_password=self._elastic_password,
        elastic_user=self._elastic_user,
    )
    logging.info("Adding events to Elasticsearch..")