This article illustrates how to build a report based on an Elasticsearch data source.
If Flexmonster is not yet embedded, set up an empty component in your webpage:
Complete the Integrating Flexmonster guide. Your code should look similar to the following example:
let pivot = new Flexmonster({ container: "pivotContainer", componentFolder: "node_modules/flexmonster/", toolbar: true });
Complete the Integration with React guide. Your code should look similar to the following example:
<FlexmonsterReact.Pivot toolbar={true} />
Complete the Integration with Angular guide. Your code should look similar to the following example:
<fm-pivot [toolbar]="true"> </fm-pivot>
Complete the Integration with Vue guide. Your code should look similar to the following example:
<Pivot toolbar />
By default, the browser prevents JavaScript from making requests across domain boundaries. CORS allows web applications to make cross-domain requests.
To enable CORS, open elasticsearch.yml
and add the following lines:
http.cors.enabled: true http.cors.allow-origin: "*" http.cors.allow-credentials: true http.cors.allow-headers: "X-Requested-With, Content-Type, Content-Length, Authorization"
To allow a connection to the Elasticsearch server from machines other than localhost, open an appropriate port in the firewall. The default port is 9200
, but it may be different depending on your configuration in the elasticsearch.yml
file.
On the client side, the report should be configured as follows (replace the node
and index
parameters with your values):
let 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" } } });
Open your webpage in the browser to see Flexmonster with your Elasticsearch data Live example.
If you run into any issues, visit our troubleshooting page.
To decrease the data loading time, you can use the dataSource.subquery property. It sets a server-side filter, so Flexmonster will get only the needed part of the data. This approach also allows you to define which data is shown on the grid.
The example below demonstrates how to load specific members of Category
and Color
fields:
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"] } }] } } } }
You may be interested in the following articles: