I have a search query for elastic which returns correct results when I run it in Kibana
{ "_source": ["name", "geotag"],
"query": {
"terms": {
"geotag": ["east", "central"]
}
},
"post_filter": {
"terms": {
"name": ["toronto", "seneca", "carleton"]
}
}
}
This above query works perfectly fine and returns the results in kibana
But when I try to run it in node.js it returns null hits. When I remove the post_filter from the query then it's working but I need the post_filter in node.js
const searchQuery = {
_source: ['_id', 'comments', '_parent', 'name', 'geotag'],
query: {
terms: {
geotag: body.locations,
},
},
post_filter: {
terms: {
name: body.rankings,
},
},
};
try {
let search = await client.search({
index: 'universities',
body: searchQuery,
});
let resolvedPromise = await Promise.all([search]);
console.log(resolvedPromise[0]);
return resolvedPromise[0];
} catch (err) {
console.log(err);
return setResponse(err.statusCode, {
message: err.message,
});
It's returning the following response in node.js
"body": {
"took": 0,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
},