Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
blendb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
23
Issues
23
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
C3SL
blendb
Commits
640217ea
Commit
640217ea
authored
Apr 22, 2019
by
Felipe Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[003] update functions
Signed-off-by:
Felipe Wu
<
felipeshiwu@gmail.com
>
parent
c070f7f8
Pipeline
#20090
failed with stages
in 26 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
13 deletions
+37
-13
src/adapter/elasticsearch.ts
src/adapter/elasticsearch.ts
+37
-13
No files found.
src/adapter/elasticsearch.ts
View file @
640217ea
...
...
@@ -2,7 +2,7 @@ import { View } from "../core/view";
import
{
Source
}
from
"
../core/source
"
;
import
{
FilterOperator
}
from
"
../core/filter
"
;
import
{
Adapter
}
from
"
../core/adapter
"
;
import
{
DataType
}
from
"
../common/types
"
;
import
{
DataType
,
AggregationType
}
from
"
../common/types
"
;
import
{
Client
,
ConfigOptions
}
from
"
elasticsearch
"
;
/** @hidden */
...
...
@@ -40,34 +40,40 @@ export class ElasticsearchAdapter extends Adapter {
}
};
/** Query is used to define the filters */
let
filter
=
{
"
match
"
:
{
"
TP_SEXO
"
:
"
2
"
}};
let
filter
=
{
"
match
"
:
{
[
view
.
clauses
[
0
].
filters
[
0
].
target
.
name
]:
view
.
clauses
[
0
].
filters
[
0
].
value
}};
let
match
=
[];
match
.
push
(
filter
);
/** Query is used to define the filters */
for
(
let
i
=
1
;
i
<
view
.
clauses
[
0
].
filters
.
length
;
i
++
)
{
filter
=
{
"
match
"
:
{
[
view
.
clauses
[
0
].
filters
[
i
].
target
.
name
]:
view
.
clauses
[
0
].
filters
[
i
].
value
}};
match
.
push
(
filter
);
}
Object
.
assign
(
query
.
query
.
bool
,
{
must
:
match
});
//console.log(JSON.stringify(initial));
console
.
log
(
JSON
.
stringify
(
view
,
null
,
2
));
/** Aggregation is used to define the dimention and the aggregation */
const
func
=
this
.
getAggregateFunction
(
view
.
metrics
[
0
].
aggregation
,
view
.
origin
);
let
aggrName
=
func
+
"
_
"
+
view
.
metrics
[
0
].
name
.
toLowerCase
();
let
aggregation
=
{
group_by
_estado
:
{
group_by
:
{
terms
:
{
field
:
"
CO_UF_NASC
.keyword
"
,
field
:
view
.
dimensions
[
0
].
name
+
"
.keyword
"
,
size
:
10000
,
order
:
{
average_idade
:
"
asc
"
[
aggrName
]
:
"
asc
"
}
},
aggs
:
{
average_idade
:
{
avg
:
{
field
:
"
NU_IDADE
"
}},
sum_idade
:
{
sum
:
{
field
:
"
NU_IDADE
"
}}
}
}
},
aggs
:
{}
}
};
Object
.
assign
(
aggregation
.
group_by
.
aggs
,
{[
aggrName
]:
{[
func
]:
{
field
:
view
.
metrics
[
0
].
name
}}});
Object
.
assign
(
query
,
{
aggs
:
aggregation
});
console
.
log
(
JSON
.
stringify
(
query
,
null
,
2
));
return
query
;
}
...
...
@@ -152,4 +158,22 @@ export class ElasticsearchAdapter extends Adapter {
*/
public
insertIntoSource
(
source
:
Source
,
data
:
any
[],
cb
:
(
err
:
Error
,
result
?:
any
[])
=>
void
):
void
{
}
private
getAggregateFunction
(
aggrType
:
AggregationType
,
origin
:
boolean
):
string
{
switch
(
aggrType
)
{
case
AggregationType
.
SUM
:
return
"
sum
"
;
case
AggregationType
.
AVG
:
return
"
avg
"
;
case
AggregationType
.
COUNT
:
return
"
value_count
"
;
case
AggregationType
.
MAX
:
return
"
max
"
;
case
AggregationType
.
MIN
:
return
"
min
"
;
default
:
return
""
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment