Query set by applying filter on java.util.hashset bin


#1

I have a set which stores bin having java.util.Set.

e.g:

nameSpace: profileData Set - profile bins name (String) id (String) channels (java.util.Set)

I stored all these values and my use case is to query profile based on channel filter. e.g: suppose we have below entries

id name channels 1 profile1 [63254,45874,56985] 2 profile2 [98547,98745,96584] 3 profile3 [65487,69857,63254]

If I pass filter channel as 63254 then profile1 and profile3 should be fetched and if i pass 98547 then profile2 should be fetched.

I tried creating secondary index on channel.

client.createIndex(null, "profileData", "profile","profile_channel_sec_idx", "channels", IndexType.NUMERIC);

And iam trying to query it by using below statement.

	Statement stmt = new Statement();
	stmt.setNamespace("profileData");
	stmt.setSetName("profile");
	for (Integer channel : channels) {
		stmt.setFilters(Filter.contains("channels", IndexCollectionType.LIST, channel));
	}
	RecordSet rs = null;
	try {
		rs = client.query(null, stmt);
		while (rs.next()) {                        --- Here it throws com.aerospike.client.AerospikeException: Error Code 201: Index not found
			// do collection of objects
		}

	} catch (AerospikeException ex) {
		throw new RuntimeException("AeroSpike Exception " + ex.getLocalizedMessage());
	} finally {
		if (rs != null)
			rs.close();
	}
}

But i get error when i do next on resultset. I am not sure where is the problem whether it is creating index or creating statement but i believe this use case is supported in aerospike.


#2

I got the problem. I was saving java.util.Set directly and because of which binary contents were shown in select query from aql. I changed java.util.Set to java.util.List so the proper integers were shown in the select query.

Post that i created list index rather than normal index which removed index not found error and I got the results.