Class: ElasticEvent

ElasticEvent

ElasticEvent

Constructor

new ElasticEvent(optionsopt)

ElasticEvent provides a simple interface to log and query event. Requests to the ElasticSearch API are sent in bulk by keeping a queue of logged events that will be sent on a set interval, before unload, on max size or on command.
Parameters:
Name Type Attributes Description
options object <optional>
elastic event defaults
Properties
Name Type Attributes Default Description
host string <optional>
localhost:9200 elasticsearch host
index string <optional>
default request index
type string <optional>
default request type
max number <optional>
256 default max queue length
interval number <optional>
10000 default interval (ms) between sending bulk requests
setupIntervalSend boolean <optional>
setups the repeating sending of bulk requests for the set interval
setupBeforeUnload boolean <optional>
setups sending bulk requests before window unload
Source:

Methods

close(optionsopt, callbackopt) → {ElasticEvent}

close empties the queue of logged events and removes the listener on beforeunload and clears interval
Parameters:
Name Type Attributes Description
options ElasticEvent~requestOptions <optional>
request options
callback ElasticEvent~requestCallback <optional>
request callback
Source:
Returns:
- chainable
Type
ElasticEvent

identify(traits) → {ElasticEvent}

identify the events with the given traits, overides previously set traits, will apply only to future events
Parameters:
Name Type Description
traits object set traits to all events
Source:
Returns:
- chainable
Type
ElasticEvent

request(dataopt, optionsopt, callbackopt) → {ElasticEvent}

request the ElasticSearch API by building the request url from options and instance defaults: url = {host}/{index}/{type}/_{op}
Parameters:
Name Type Attributes Description
data object | string <optional>
body content of the request
options ElasticEvent~requestOptions <optional>
request options
callback ElasticEvent~requestCallback <optional>
request callback
Source:
Returns:
- chainable
Type
ElasticEvent
search using the ElasticSearch API with the given body query
Parameters:
Name Type Attributes Description
query external:requestBodySearch <optional>
body search
options ElasticEvent~requestOptions <optional>
options
callback ElasticEvent~requestCallback <optional>
callback
Source:
Returns:
- chainable
Type
ElasticEvent

send(optionsopt, callbackopt) → {ElasticEvent}

send the bulk queued requests
Parameters:
Name Type Attributes Description
options ElasticEvent~requestOptions <optional>
request options
callback ElasticEvent~requestCallback <optional>
request callback
Source:
Returns:
- chainable
Type
ElasticEvent

track(type, eventopt) → {ElasticEvent}

track events you will need to specify the event type, this will mixin the event with this.traits and add it to the queued requests
Parameters:
Name Type Attributes Description
type string event type
event object <optional>
event/document data
Source:
Throws:
'invalid type' if type parameter is not a string
Returns:
- chainable
Type
ElasticEvent

Type Definitions

requestCallback(error, response, status)

This callback is displayed as part of the Requester class.
Parameters:
Name Type Description
error Error | null
response external:response | object | null
status number
Source:

requestOptions

Type:
  • object
Properties:
Name Type Attributes Default Description
url string <optional>
overides request url construction
host string <optional>
this.host request host
index string <optional>
this.index request index
type string <optional>
this.type request type
op string <optional>
search request operation
sync boolean <optional>
synchronous request
Source: