Despite the COVID-19 outbreak, our team continues operating at full speed. We are always here to support and answer all your questions.

Feel free to reach out by filling this quick form.

Fill the form
Get Free Trial

Problem with ElasticSearch connection

Answered
Ilia Bocharov asked on June 5, 2020

Hi all!
I’ve tried connect Flexmonster in Angular 9 application to remote Elasticsearch cluster. Cluster have gateway and can proceed request on 443 port only. When i try to use node and requestHeaders config like:

  public esReport = {
dataSource: {
dataSourceType: 'elasticsearch',
node: 'https://elasticsearch-remote.host.com',
requestHeaders: {
'Authorization': "Basic dGVzdDp0ZXN0",
'Access-Control-Allow-Origin': "*",
'Access-Control-Allow-Headers': "Accepted",
'Access-Control-Allow-Credentials': "true"
},
mapping: {
"_index": {
"visible": false
},
},
/* the name of Elasticsearch index to connect */
index: 'real-index'
}
};


I’ve got wrong call with few issues:

in url was duplicated slash:
https://elasticsearch-remote.host.com/real-index//_mapping ;

And all defined headers had undefined as value.
Then i’ve tried to use host object: 

public esReport = {
dataSource: {
dataSourceType: 'elasticsearch',
host: [
{
protocol: "https",
host: "elasticsearch-remote.host.com",
port: 443,
headers: {
'Authorization': "Basic dGVzdDp0ZXN0",
'Access-Control-Allow-Origin': "*",
'Access-Control-Allow-Headers': "Accepted",
'Access-Control-Allow-Credentials': "true"
},
path: null,
}
],
index: 'real-index'
}
};

I’ve got https://undefined/real-index/_mapping without any headers.
And one more problem:
in

interface FlatSort {
sort: "asc" | "desc" | "unsorted";
uniqueName: string;
}

sort type have wrong type. For correct configuration i need cast value like :

sort: "asc" as "asc"

.
Thanks in advance.

7 answers

Public
Dmytro Zvazhii Flexmonster June 9, 2020

Hello Ilia,
Thank you for providing us with the samples to reproduce.
We are going to investigate the issue with Elasticsearch connection and will provide you with the results ETA Jul 13.
As for FlatSort interface, we have checked the following approach with Typescript 3.4.5:

sort: FlatSort = {
sort: "asc",
uniqueName: "Column"

and everything works as expected.
Does it work for you?

 
Please let us know in case of any other question.
Regards,
Dmytro
 

Public
Ilia Bocharov June 11, 2020

For FlatSort : I use Typescript 3.7.5 and define report datasourse as JSON. In that JSON i’ve tried define 

public pivotReport = {
dataSource: {
data: this.reportData,
},
slice: {
flatSort: [
{
sort: "asc",
uniqueName: "id",
}
]
},
options: {
grid: {
type: "classic",
showTotals: false,
showGrandTotals: "off"
}
}
};

and then i got: 

TS2345: Argument of type '{ dataSource: { data: ReportModel[]; }; slice: { rows: { uniqueName: string; }[]; columns: { uniqueName: string; }[]; measures: { uniqueName: string; aggregation: string; }[]; flatOrder: string[]; flatSort: { ...; }[]; }; options: { ...; }; }' is not assignable to parameter of type 'Report'.  
The types of 'slice.flatSort' are incompatible between these types.    
Type '{ sort: string; uniqueName: string; }[]' is not assignable to type 'FlatSort[]'.       Type '{ sort: string; uniqueName: string; }' is not assignable to type 'FlatSort'.         
Types of property 'sort' are incompatible.           
Type 'string' is not assignable to type '"asc" | "desc" | "unsorted"'.

for

this.pivot.flexmonster.setReport(pivotReport);

and when i’ve cast sort :

flatSort: [
{
sort: "asc" as "asc",
uniqueName: "id",
}
]

i got no issue. 
I think sort type can be enum.

interface FlatSort {
sort: Sort;
uniqueName: string;
}

enum Sort {
asc,
desc,
unsorted
}
Public
Dmytro Zvazhii Flexmonster June 12, 2020

Hello Ilia,
Thank you for sharing your feedback.

Yes, you are right. For such typeless object like pivotReport Typescript compiler cannot match FlatSort.sort type with the expected one. Still, a small hack can do the trick, here is the example:

public pivotReport: Flexmonster.Report = {...

With such an approach Typescript compiler should not complain.

We do agree that the current approach may be counter-intuitive and sometimes uncomfortable. Therefore, we are going to replace it with a more general approach such as string ETA Jun 15. It will look something like this:

interface FlatSort {
sort: string;
uniqueName: string;
}

Meanwhile, we suggest using the mentioned above workaround.

Please let us know if everything works fine.
Regards,
Dmytro

Public
Mykhailo Halaida Mykhailo Halaida Flexmonster June 17, 2020

Hi Ilia,
 
We are glad to announce that the FlatSort.sort property was set to the string type.
 
This is included in the 2.8.9 version of Flexmonster: https://www.flexmonster.com/release-notes/
You are welcome to update the component. Here is our updating to the latest version guide for assistance: https://www.flexmonster.com/doc/updating-to-the-latest-version/ 
 
We are also currently working on the mentioned Elasticsearch connection issue and will return to you next month, as previously suggested. 
 
Please let us know if everything works fine for you.
 
Best regards,
Mykhailo

Public
Ilia Bocharov June 17, 2020

Hello, Mykhailo! 
Thanks a lot! FlatSort.sort works fine.
 
Regards, 
Ilia Bocharov.

Public
Mykhailo Halaida Mykhailo Halaida Flexmonster July 14, 2020

Hi Ilia,
 
We are pleased to inform you that for Elasticsearch, the issues with adding odd slash into the node URL & adding custom request headers were fixed.
 
This is available in the 2.8.11 version of Flexmonster: https://www.flexmonster.com/release-notes/
 
You are welcome to update the component. Here is our updating to the latest version guide for assistance: https://www.flexmonster.com/doc/updating-to-the-latest-version/ 
 
Please contact us in case any questions arise.
 
Best regards,
Mykhailo

Public
Mykhailo Halaida Mykhailo Halaida Flexmonster July 22, 2020

Hi Ilia,
 
Hope you’re doing well.
 
We were wondering if you’ve had a chance to check out the recent fix we’ve mentioned in our previous response. Have the issues been fixed on your side? 
 
We would be happy to hear your feedback.
 
Regards,
Mykhailo

Please login or Register to Submit Answer