Handling response object

how to extract a single field from the result hits of full text search query?
For example:
I have indexed all fields of doucuments like this.
{
“callsign”: “TXW”,
“country”: “United States”,
“iata”: “TQ”,
“icao”: “TXW”,
“id”: 10123,
“name”: “Texas Wings”,
“type”: “airline”
}

For any FTS query, I want to extract 'id ’ fields of all my search hits.
How to do this?
I am new to this. Any help appreciated!

Hi @Rajeev_Bhat,

You may pass the document field names which you want to retrieve as a part of the search request in the Fields: argument.
ref- https://docs.couchbase.com/server/current/fts/fts-response-object-schema.html#request

Just remember to store those fields as apart of the index definition by ticking the “store” checkbox against the necessary field mappings.

eg: curl -XPOST -H “Content-Type: application/json” -u -p . http://host:port/api/index//query -d ‘{
“fields”: [
“country” /// name of the field you wish to retrieve
],
“query”: {
“query”: “sea”
}
}’

Cheers!

1 Like

Thank you very much @sreeks !!