Ejemplo n.º 1
0
    def _prepare_record(record, index, doc_type, arguments=None, **kwargs):
        """Prepare record data for indexing.

        :param record: The record to prepare.
        :param index: The Elasticsearch index.
        :param doc_type: The Elasticsearch document type.
        :param arguments: The arguments to send to Elasticsearch upon indexing.
        :param **kwargs: Extra parameters.
        :return: The record metadata.
        """
        if current_app.config['INDEXER_REPLACE_REFS']:
            data = record.replace_refs().dumps()
        else:
            data = record.dumps()

        data['_created'] = pytz.utc.localize(record.created).isoformat() \
            if record.created else None
        data['_updated'] = pytz.utc.localize(record.updated).isoformat() \
            if record.updated else None

        # Allow modification of data prior to sending to Elasticsearch.
        before_record_index.send(
            current_app._get_current_object(),
            json=data,
            record=record,
            index=index,
            doc_type=doc_type,
            arguments={} if arguments is None else arguments,
            **kwargs)
        return data
Ejemplo n.º 2
0
 def _prepare_record(self, record, index, doc_type):
     data = record.serialize_for_es()
     before_record_index.send(
         current_app._get_current_object(),
         json=data,
         record=record,
         index=index,
         doc_type=doc_type,
     )
     return data
Ejemplo n.º 3
0
 def _prepare_record(record,
                     index,
                     doc_type="_doc",
                     arguments=None,
                     **kwargs):
     data = record.serialize_for_es()
     before_record_index.send(
         current_app._get_current_object(),
         json=data,
         record=record,
         index=index,
         doc_type=doc_type,
         arguments={} if arguments is None else arguments,
         **kwargs)
     return data