Thank you everyone for your help.
I have made the correct JS code, I hope it will help others :
var users = {}
var N = 20;
var arr = Array.apply(null, { length: N }).map(Number.call, Number)
client.msearch({
body: [].concat.apply([], arr.map((number) => ([
{ index: 'my_index' },
{
"size": 0,
"aggs": {
"my_terms": {
"terms": {
"field": "user_id",
"include": {
"partition": number,
"num_partitions": 20
},
"size": 10000
}
}
}
}
])))
}, (err, result) => {
if (err) {
console.log(err)
}
else {
result.responses.forEach(resp => {
resp.aggregations.my_terms.buckets.forEach(term => {
if (!users[term.key]) {
users[term.key] = 1
}
})
})
console.log(Object.keys(users).length)
}
})
I don't know if I'm choosing the right number of size & num_partitions.
While i know that the approximate number is near to 200k, so I have made 20 partitions of 10k.
Please @Mark_Harwood if this is the correct way to choose the size & num_partitions.
Thank you.