Querying data with arry of promises


#1

Hey i’m new here, and i have a problem with Querying data using an array of promises building each promise with the .execute() method like this:

let result = ['company_name','customer_name'].map(item => (
    cf.provider('Elasticsearch')
		.source('my_source')
		.groupby(cf.Attribute(`${item}`).limit(100).sort('desc'))
		.textfilter(`${item}:*a*`)
		.limit(100)
		.execute()
));

Promise.all(result);

When I try to build the promises array I get this error:


#2

Hi @ralf it seems like you are not including an ID in your query, for that reason the toolkit is assigning a default id, which will overwrite the previous promise, try with .element('my_id') for each query, also you can review the docs for querying data.


#3

Hey @emoya thank you so much, you have the reason, adding an id to the query enables me to create an array of promises properly, now the code works good and looks like this:

let result = ['company_name','customer_name'].map(item => (
    cf.provider('Elasticsearch')
		.source('my_source')
		.groupby(cf.Attribute(`${item}`).limit(100).sort('desc'))
		.textfilter(`${item}:*a*`)
        .element(`${item}-qid`)
		.limit(100)
		.execute()
));

Promise.all(result);