Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const axios = require('axios');
module.exports.getDatasetInfoFromES = async (elasticsearchUrl, layer, fields, cookies, pathToFile) => {
let options = {
method: 'POST',
url: `${elasticsearchUrl}/_search?request_cache=false`,
data: {
"from": 0,
"size": 1,
"_source": fields,
"query": {
"term": {
"metadata-fr.link.name.keyword": layer
}
}
},
};
if (pathToFile) {
options = {
method: 'POST',
url: `${elasticsearchUrl}/_search?request_cache=false`,
data: {
"from": 0,
"size": 1,
"_source": fields,
"query": {
"bool": {
"should": [
{
"term": {
"metadata-fr.link.name.keyword": layer
}
},
{
"match_phrase": {
"metadata-fr.link.url": {
"query": pathToFile
}
}
}
]
}
}
}
};
}
if (cookies) {
options.headers = {
cookie: cookies,
};
}
let response;
try {
response = await axios(options)
} catch (err) {
throw {
err,
status: 500,
message: "Request to Elasticsearch failed",
};
}
// If no results are found it means the specified dataset mvt layer doesn't exists
if (response.data.hits.hits < 1) {
throw {
status: 404,
message: "Layer not found.",
};
}
return response.data.hits.hits[0]._source;
};