This tutorial explains how to define a mapping
object for an Elasticsearch index in a report and which settings this object supports.
A mapping
object can have the following properties:
caption
optional — String. Overrides the default name of the field.aggregations
optional — Array of strings. Represents the list of aggregation functions that can be applied to the current measure.filters
optional — Boolean. Allows enabling and disabling the UI filters for a specific field. When set to false
, the UI filters are disabled. Default value: true
. visible
optional — Boolean. When set to false
, hides the field from the Field List.calendar_interval
optional — String. Sets the Elasticsearch’s calendar_interval parameter for the date histogram. This parameter allows rounding down dates by the given interval. For example, if the calendar_interval
is "day"
, 2021-05-25T19:30:00
will be rounded to 2021-05-25T00:00:00
. See an example on JSFiddle."day"
.
fixed_interval
optional — String. Sets the Elasticsearch’s fixed_interval parameter for the date histogram. This parameter allows rounding down dates by the given interval. For example, if the fixed_interval
is "3h"
, 2021-05-25T19:30:00
will be rounded to 2021-05-25T18:00:00
. See an example on JSFiddle.interval
optional — String. Sets the Elasticsearch’s interval
parameter for the date histogram. This parameter allows rounding down dates by the given interval. For example, if the interval
is "day"
, 2021-05-25T19:30:00
will be rounded to 2021-05-25T00:00:00
. Check out the list of supported intervals.interval
was deprecated in Elasticsearch version 7.2 and removed in version 8. If your Elasticsearch version is higher than 7.2, use either calendar_interval or fixed_interval properties instead of the interval
.time_zone
optional — String. Used for the date histogram. You can specify time zones as either an ISO 8601 UTC offset (e.g., +01:00
or -08:00)
or as a time zone ID as specified in the IANA time zone database, such as America/Los_Angeles
. Check out this example.format
optional — String. Used for the date histogram. Check out the supported date format/patterns.format
will override its value for the field.min_doc_count
optional — Number. Used for the date histogram. Can be used to show intervals with empty values (min_doc_count: 0
). Default value: 1
(empty intervals are hidden).All unnecessary fields can be hidden by setting visible: false
:
var pivot = new Flexmonster({
container: "pivotContainer",
toolbar: true,
report: {
dataSource: {
type: "elasticsearch",
/* the host for the connection */
node: "https://olap.flexmonster.com:9200",
/* the name of Elasticsearch index to connect */
index: "fm-product-sales",
/* additional setting to configure index mapping */
mapping: {
"@timestamp": {
visible: false
},
"@version": {
visible: false
},
"host": {
visible: false
},
"message": {
visible: false
},
"path": {
visible: false
}
}
}
}
});
Check out the example on JSFiddle.
There are two ways to format dates in Elasticsearch:
mapping.format
property – this will apply formatting to a certain field. If options.datePattern
is defined, mapping.format
will override its value.When formatting dates with the options.datePattern
property, use date patterns described in the Elasticsearch documentation.
The following example demonstrates how to format dates using the options.datePattern
:
new Flexmonster({
container: "pivotContainer",
toolbar: true,
report: {
dataSource: {
type: "elasticsearch",
node: "https://olap.flexmonster.com:9200",
index: "fm-product-sales"
},
options: {
datePattern: "dd MMMM, yyyy"
}
}
});
See the full code on JSFiddle.
When formatting dates with the mapping.format
property, use date patterns described in the Elasticsearch documentation.
The following example demonstrates how to format dates using mapping.format
:
new Flexmonster({
container: "pivotContainer",
toolbar: true,
report: {
dataSource: {
type: "elasticsearch",
node: "https://olap.flexmonster.com:9200",
index: "fm-product-sales",
mapping: {
"@timestamp": {
format: "dd/MM/yyyy"
}
}
}
}
});
Check out the example on JSFiddle.
Elasticsearch date patterns are fully applied to dates in the pivot and compact views, while dates in the drill-through view may remain unformatted.
If you need a date pattern that is applied in all the views similarly, format date fields using patterns supported in both Flexmonster and Elasticsearch:
d
– Day of the month. It is represented as a one or two-digit number. For example, 2 or 18.
dd
– Day of the month. It is represented as a two-digit number. For example, 02 or 18.
M
– Month. It is represented as a one or two-digit number. For example, 3 or 11.
MM
– Month. It is represented as a two-digit number. For example, 03.
MMM
– Month. It is represented as a three-letter abbreviation of the name of the month. For example, Mar.
MMMM
– Month. It is represented as the full name of the month. For example, March.
yy
– Year. It is represented as a two-digit number. For example, 16.
yyyy
– Year. It is represented as a four-digit number. For example, 2016.
h
– Hour of the day using the 12-hour format [1 – 12]. It is represented as a one or two-digit number. For example, 1 or 12.
hh
– Hour of the day using the 12-hour format [1 – 12]. It is represented as a two-digit number. For example, 01 or 12.
H
– Hour of the day using the 24-hour format [0 – 23]. It is represented as a one or two-digit number. For example, 0 or 23.
HH
– Hour of the day using the 24-hour format [0 – 23]. It is represented as a two-digit number. For example, 00 or 23.
k
– Hour of the day using the 24-hour format [1 – 24]. It is represented as a one or two-digit number. For example, 1 or 24.
kk
– Hour of the day using the 24-hour format [1 – 24]. It is represented as a two-digit number. For example, 01 or 24.
m
– Minutes [0 – 59]. It is represented as a one or two-digit number. For example, 0 or 59.
mm
– Minutes [0 – 59]. It is represented as a two-digit number. For example, 00 or 59.
s
– Seconds [0 – 59]. It is represented as a one or two-digit number. For example, 0 or 59.
ss
– Seconds [0 – 59]. It is represented as a two-digit number. For example, 00 or 59.