Optimize data loading using subqueries in Elasticsearch

Data source

by Flexmonster Pivot Table

HTML

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

<div>
  <h2>How to optimize data loading using subqueries in Elasticsearch</h2>
  <p>
  This example demonstrates how to load the data from Elasticsearch faster.
  </p>
  <p>
  Using the <code>dataSource.subquery</code> property, you can set a server-side filter for your data. As a result, Flexmonster will get only the needed subset of the data. In this example, we load specific members of the <code>Category</code> and <code>Color</code> fields (lines 12-26 in the JavaScript box).
  </p>
  <p>
  <a href="https://www.flexmonster.com/doc/connecting-to-elasticsearch/" target="_blank">See our documentation for more details on connecting to Elasticsearch</a>.
  </p>
</div>

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

CSS

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

JavaScript

new Flexmonster({
  container: "#pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  width: "100%",
  height: 600,
  toolbar: true,
  report: {
    dataSource: {
      type: "elasticsearch",
      node: "https://olap.flexmonster.com:9200",
      index: "fm-product-sales",
      subquery: {
        bool: {
          filter: [{
              terms: {
                "Category.keyword": ["Bikes", "Accessories"],
              }
            },
            {
              terms: {
                "Color.keyword": ["blue", "red"]
              }
            }
          ]
        }
      },
      mapping: {
        "@timestamp": {
          visible: false
        },
        "@version": {
          visible: false
        },
        "host": {
          visible: false
        },
        "message": {
          visible: false
        },
        "path": {
          visible: false
        }
      }
    },
    slice: {
      rows: [{
          uniqueName: "Category.keyword",
          caption: "Category"
        }
      ],
      columns: [{
        uniqueName: "Color.keyword",
        caption: "Color"
      }, {
        uniqueName: "[Measures]"
      }],
      measures: [{
        uniqueName: "Price",
        aggregation: "sum",
        caption: "Price"
      }]
    }
  }
});