This repository has been archived by the owner on Jun 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.js
69 lines (60 loc) · 1.61 KB
/
query.js
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
const Config = require('./lib/config');
const fetch = require('node-fetch');
const { ELASTICSEARCH_ADDRESS, ELASTICSEARCH_INDEX_NAME } = Config;
const query = {
size: 100,
query: {
nested: {
path: "about",
query: {
function_score: {
query: {
terms: {
"about.id": [ "http://dbpedia.org/resource/Linear_algebra" ]
}
},
field_value_factor: {
field: 'about.score'
}
}
}
}
// function_score: {
// query: {
// terms: {
// "about.id": [ "http://dbpedia.org/resource/Linear_algebra" ],
// }
// },
// // field_value_factor: {
// // field: 'about.score'
// // }
// }
// match: {
// "about.id": "http://dbpedia.org/resource/Linear_algebra"
// }
// has_child: {
// type: "Annotation",
// query: {
// terms: {
// about: [ annotation["about"] ]
// }
// }
// }
}
};
async function testQuery() {
const url = `${ELASTICSEARCH_ADDRESS}/${ELASTICSEARCH_INDEX_NAME}_resources_search/Resource/_search`;
console.log('Testing query against url:', url);
const resourcePromise = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(query)
});
const resources = await resourcePromise.json();
console.log('Response:', resources);
const result = resources.hits.hits.map(hit => hit._source);
return result.map(hit => hit["@id"]);
}
testQuery().then(console.log.bind(console), console.error.bind(console));