Format all date fields in Elasticsearch

Options

by Flexmonster Pivot Table

HTML

<script src="https://cdn.flexmonster.com/flexmonster.js"></script>

<div>
  <h2>How to format all date fields in Elasticsearch</h2>
  <p>
    This example demonstrates how to apply formatting to all date fields in
    Elasticsearch.
  </p>
  <p>
    To format all date fields in Elasticsearch, use the
    <code>options.datePattern</code> property.
  </p>
  <p>
    <a
      href="https://www.flexmonster.com/doc/configuring-the-mapping/#set-date-format"
      target="_blank"
    >See our docs to learn more about date formatting and supported date patterns</a>.
  </p>
</div>

<div id="pivot-container"></div>

CSS

@import url(https://cdn.flexmonster.com/assets/jsfiddle-styles.css);

JavaScript

let pivot = new Flexmonster({
  container: "#pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  width: "100%",
  height: 400,
  report: {
    dataSource: {
      type: "elasticsearch",
      node: "https://olap.flexmonster.com:9200",
      index: "australian_weather"
    },
    options: {
    	datePattern: "dd MMMM, yyyy",
      showAggregationLabels: false,
      grid: {
      	showTotals: "off",
        showGrandTotals: "off"
      }
    },
    slice: {
      rows: [ 
      	{ 
        	uniqueName: "Date",
          filter: {
          	query: {
            	after: "2017-05-31"
            }
          }
        } 
      ],
      columns: [
      	{ uniqueName: "State.keyword" },
        { uniqueName: "[Measures]" }
      ],
      measures: [
      	{
        	uniqueName: "Max Temperature",
        	format: "-10ws2q1oviodoa"
      	}
    	]
    },
    formats: [
    	{
      	name: "",
        decimalPlaces: 1
      },
      {
        name: "-12d55123ugyhur",
        currencySymbol: " km&#x2F;h",
        positiveCurrencyFormat: "1$",
        negativeCurrencyFormat: "-1$"
      },
      {
        name: "-10ws2q1oviodoa",
        currencySymbol: " &deg;C",
        positiveCurrencyFormat: "1$",
      	negativeCurrencyFormat: "-1$"
      }
    ]
  }
});