Get Free Trial
  1. API reference
Connecting to Data Source
  1. Supported data sources
  2. Connecting to other data sources
Configuring the component
  • Documentation for older versions
  • Table of contents

    Configuring the mapping

    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.
      See the list of supported intervals: Calendar intervals.
      Only for Elasticsearch version 7.2 and higher.
      Default value: "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.
      See the list of supported intervals: Fixed intervals.
      Only for Elasticsearch version 7.2 and higher.
    • 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.
      Note that the 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.
      If the datePattern option is defined, 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).

    How to hide unnecessary fields in Elasticsearch

    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.

    How to format dates in Elasticsearch

    There are two ways to format dates in Elasticsearch: 

    • Using the options.datePattern property – this will apply formatting to all date fields in the dataset. 
    • Using the mapping.format property – this will apply formatting to a certain field. If options.datePattern is defined, mapping.format will override its value.

    options.datePattern

    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.

    mapping.format

    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.

    Formatting dates in the drill-through view

    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:

    Supported date patterns

    Expand the list of the date patterns
    • 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.