Flexmonster Software License Agreement (“Agreement”) has been revised and is effective as of January 8, 2025.
The following modifications were made:
The modified version of Agreement is available here.
Downloading, installing, and/or continuing to use Flexmonster Software after January 8, 2025, constitutes Licensee’s acceptance of the terms and conditions of the modified version of Agreement. If Licensee does not agree to any of these terms and conditions, they must cease using Flexmonster Software and must not download, install, use, access, or continue to access Flexmonster Software. By continuing to use Flexmonster Software or renewing the license or maintenance after the effective date of these modifications to Agreement, Licensee accepts and agrees to be bound by the terms and conditions of the modified Agreement.
This article illustrates how to build a report based on data from Elasticsearch.
Skip this step if you have already set up Elasticsearch. Otherwise, start from this guide: Download Elasticsearch.
By default, Elasticsearch blocks cross-domain requests. To allow Flexmonster to connect to your Elasticsearch index, you must enable CORS in Elasticsearch.
To enable CORS, open the elasticsearch.yml
file. Then, add or update the following lines:
http.cors.enabled: true
# On production, use the domain where Flexmonster is running
http.cors.allow-origin: "*"
http.cors.allow-credentials: true
http.cors.allow-headers: "X-Requested-With, Content-Type, Content-Length, Authorization"
Note To allow a connection to the Elasticsearch server from a different machine, 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.
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:
const pivot = new Flexmonster({
container: "pivotContainer",
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 />
On the client side, configure the report based on whether security is enabled or disabled in Elasticsearch:
If you have security enabled, include the Authorization
header in the dataSource.requestHeaders property to authenticate requests:
const pivot = new Flexmonster({
container: "pivotContainer",
toolbar: true,
report: {
dataSource: {
type: "elasticsearch",
// Your secured Elasticsearch endpoint
node: "https://localhost:9200",
// The name of your Elasticsearch index
index: "fm-product-sales",
requestHeaders: {
Authorization: "Basic " + btoa("<your_username>:<your_password>")
}
},
}
});
In the code above, the btoa() method is used to Base64-encode the credentials, which are required for securing HTTP client applications.
const pivot = new Flexmonster({
container: "pivotContainer",
toolbar: true,
report: {
dataSource: {
type: "elasticsearch",
// Your Elasticsearch endpoint
node: "https://olap.flexmonster.com:9200",
// The name of your Elasticsearch index
index: "fm-product-sales"
}
}
});
See the full list of Flexmonster properties used to configure the dataSource
object.
When connecting to data from Elasticsearch, you can use the following properties of the DataSourceObject:
Property/Type | Description |
---|---|
type String | The data source type. When connecting to data from Elasticsearch, set the type to "elasticsearch" . |
node String | The URL to the Elasticsearch endpoint. |
index Boolean | The name of the Elasticsearch index. |
mapping MappingObject | String | optional Defines how fields from the data source are treated and presented within the component. For example, you can specify the field’s captions or hide the field from the dataset. Read more about configuring the mapping in Elasticsearch. It can be either an inline MappingObject or a URL to a JSON file with the mapping Live example. |
subquery BoolQueryObject | optional Sets a server-side filter to decrease the size of the response from the server Live example. |
requestHeaders Object | optional Adds custom request headers. Consists of "key": "value" pairs, where "key" is a header name and "value" is its value
Live example.Note The requestHeaders property is not saved when obtaining the report via save() and getReport() API calls. |
withCredentials Boolean | optional Indicates whether cross-site Access-Control requests should be made using credentials such as authorization headers (true ) or not (false ). For more details, refer to MDN web docs.Setting the withCredentials flag to true is recommended when using Windows authentication and other types of server authentication. When set to false , the browser does not ask for credentials and does not include them in outgoing requests.Default value: false . |
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"]
}
}]
}
}
}
}
If you need to add custom authentication or manually handle requests on the backend, try out our sample project, which connects Flexmonster to Elasticsearch using a proxy server.