How to use select on azure search suggesters

youssef125 266 Reputation points
2022-06-02T08:53:55.517+00:00

'm using Azure search on my project, and I want to do an autocomplete text field, it works as expected. here's the code :

const suggestItems = async (req, res) => {

try {

// Reading inputs from HTTP Request

const q = (req.query.q || (req.body && req.body.q));

const top = (req.query.top || (req.body && req.body.top));

const suggester = (req.query.suggester || (req.body && req.body.suggester));

// Let's get the top 5 suggestions for that search term

const suggestions = await client.suggest(q, suggester, {  top: parseInt(top) });

//const suggestions = await client.autocomplete(q, suggester, {top: parseInt(top)});

console.log(suggestions.results)

return res.status(status.OK)

.json({ suggestions: suggestions.results})

 

} catch (error) {

handleError(res, error)

}

}
her's the result :

[

{ text: 'Alpha Aromatics (MA)', document: { id: '4' } },

{ text: 'Alpha Aromatics (USA)', document: { id: '5' } },

{ text: 'Art Land - Winter Palace', document: { id: '6' } },

{ text: 'Alpha Aromatics (USA)', document: { id: '3' } }

]
here's the quesry passed by postman :

{

"q":"ar","top":5,"suggester":"sg"

}
but the problem is , on the result I have just the text and the id of the document , I'm looking for other fields like status for example, how can get that please ?

Azure Cognitive Search
Azure Cognitive Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
195 questions
No comments
{count} votes

1 answer

Sort by: Most helpful
  1. ajkuma 13,456 Reputation points Microsoft Employee
    2022-06-03T09:58:31.477+00:00

    youssef125-3012,

    "You need to make sure you mark the fields you need to be returned in the results as retrievable in your index definition. It looks you only have text and id fields as retrievable.
    Mark "Status" as one of your index fields. For more information: search-what-is-an-index.

    -You should use select for each field. For more details of how to use it or any other options to manipulate the results, you can see the sample code here: Search an index."

    --Copied the answer suggested by Gia Mondragon - MSFT (our PG from Azure Search team) to benefit the community here, please continue your discussion on SO thread.

    Example:

    hotels-sample-index

    --

    To benefit the community find the right answers, please do mark the post which was helpful by clicking on Accept Answer’ & ‘Up-Vote’.