Elastic Search Code :
POST /_msearch
{ "index": "INDEX_NAME_1", "type": "TYPE_NAME_1" }
{ "query": { "match_all": {}}}
{ "index": "INDEX_NAME_2", "type": "TYPE_NAME_2" }
{ "query": { "match_all": {}}}
Reference link http://teknosrc.com/execute-multiple-search-query-elasticsearch/#comment-8578 (Refer example 1)
Node js code :
return new Promise(function (resolve, reject) {
elasticClient.search({
index: '*:logstash-prod-*',
type: 'callEnd',
size: 10000,
body: {
query: {
range: {
"@timestamp": {
"gte": startTime,
"lte": endTime
}
}
}
},
}, function (error, response, status) {
if (error) {
reject(error);
}
else {
console.log("show the response" + JSON.stringify(response));
let elasticResponse=response.hits.hits;
resolve(response);
}
})
});
Above node js query works for one type:"callEnd". Please help in converting the Elastic code (two types) to node js code.
Here is msearch documentation.
In your case it'll be something like this:
const queryBody = [
{ index: '*:logstash-prod-*', type: 'callEnd1' },
{
query: {
range: {
'@timestamp': {
'gte': startTime,
'lte': endTime
}
}
},
size: 10000
},
{ index: '*:logstash-prod-*', type: 'callEnd2' },
{
query: {
range: {
'@timestamp': {
'gte': startTime,
'lte': endTime
}
}
},
size: 10000
}
];
return elasticClient
.msearch({ body: queryBody })
.then(result => {
console.log('show the response' + JSON.stringify(result));
return result;
})
.catch(error => {
// TODO Handle error here.
});
Note that msearch returns promise itself, so no need to create it yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With