Get array value

I want to select a value on the basis of an array of key elements. Please suggest an index with the query .

“addressDetails”: {
“R”: {
“city”: “XYZ”,
}
on the basis of city i want to select .

.

Could you please post your query and what you tried.
If you need index use index advisor https://query-tutorial.couchbase.com/tutorial/#55

“addressDetails”: {
“R”: {
“city”: “XYZ”,
}

“R”: {
“city”: “ABC”,
}

}

In the above array I want to select the same item where the city name is ABC.

There is no ARRAY in your JSON. You have posted object. Based on object you can write query like this

SELECT    addressDetails.R.city
FROM  default 
WHERE  addressDetails.R.city = "ABC";

If addressDetails is array like below

{ "addressDetails": [{ "R": { "city": "XYZ" }}, { "R": { "city": "ABC" } } ] }

CREATE INDEX ix1 ON default (ALL v.R.city FOR v IN addressDetails END);

Depends on output format use one of these.

SELECT d.*
FROM default AS d
WHERE ANY v IN d.addressDetails SATISFIES v.R.city = "ABC" END

OR

(Make sure UNNEST alias (i.e. v)  match with binding variable (i.e. v) in CREATE INDEX statement
SELECT v.*
FROM default AS d
UNNEST d.addressDetails AS v
WHERE v.R.city = "ABC" ;

If addressDetails is dynamic object like below

{ "addressDetails": { "R1": { "city": "XYZ" },  "R2": { "city": "ABC" } } }

CREATE INDEX ix1 ON default (ALL v.city FOR v IN OBJECT_VALUES(addressDetails) END);

SELECT d.*
FROM default AS d
WHERE ANY v IN OBJECT_VALUES(d.addressDetails) SATISFIES v.city = "ABC" END;

If you need search on arrays take look


https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/indexing-arrays.html

If you still need help please post complete input document and expected output.