Need a special offer?Find out if your project fits.
+
All documentation
  • Introduction
  • Connecting to Data Source
    1. Supported data sources
    2. Connecting to other data sources
  • Browser compatibility
  • Documentation for older versions
  • 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.

    Available properties

    The mapping object can have the following properties:

    Property/TypeDescription
    caption
    String
    optional Overrides the default name of the field.
    aggregations
    String[]
    optional Represents the list of aggregation functions that can be applied to the current measure.
    filters
    Boolean
    optional Allows enabling and disabling the UI filters for a specific field. When set to false, the UI filters are disabled.
    Default value: true.
    visible
    Boolean
    optional When set to false, hides the field from the Field List.
    calendar_interval
    String
    optional 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
    String
    optional 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
    String
    optional 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
    String
    optional 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
    String
    optional Used for the date histogram. Check out the supported date format/patterns.
    If options.datePattern is defined, the format will override its value for the field.
    min_doc_count
    Number
    optional 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",
      componentFolder: "node_modules/flexmonster/",
      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 format property in the mapping - this will apply formatting to a certain field. If options.datePattern is defined, the 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",
      componentFolder: "node_modules/flexmonster/",
      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.

    format

    When formatting dates with the format property in the mapping, use date patterns described in the Elasticsearch documentation.

    The following example demonstrates how to format dates using the format:

    new Flexmonster({
      container: "pivotContainer",
      componentFolder: "node_modules/flexmonster/",
      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 classic and compact forms, 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:

    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.