I have a function that requires an aggregation for each word entered by the user and then generates a chart.
I am wondering how I can access the value of the variable i from my loop in the callback when the request is made.
Is there a way to include the variable i in the predefined parameters set by the elasticsearch API?
for(var i = 0; i < 15; i++)
{
client.search({
index: 'twitter',
type: "status",
size : 10,
body:
{
query: {
"bool": {
"must": [
{"query_string": {
"fields" : ["text"],
"default_operator" : "AND",
"query" : $scope.motsCompares[i]
}},
{"range": {
"created_at": {
"gte": moment().subtract(duration, key).format("YYYY-MM-DD")
}
}}
]
}
},
aggs : {
"frequence_mots" : {
"date_histogram" : {
"field" : "created_at",
"interval" : "day",
"format" : "dd/MM/yyyy",
"min_doc_count" : 0
}
}
}
}
}).then(function traiterResultat(body) {
// Here's where I want to refer to the current i value from the loop to access the right word in my array ($scope.motsCompares[i])
}, function (error) {
console.trace(error.message);
});
}