I have gone through https://download.aerospike.com/docs/guide/cdt-map-index-and-query.html page and successfully created an index on MAP bin.
I can query as well from aql. However I am finding it difficult to write the same in C# syntax.
Following is my C# statement code:
var statement = new Statement();
statement.SetNamespace("core");
statement.SetSetName("zings");
statement.SetIndexName("i_zings_meta");
statement.SetBinNames("meta");
statement.SetFilter(Filter.Equal("meta", "[value of key]"));
return statement;
When I query the recordset using this statement I get nothing. When I do the same on aql I get my result. What am I missing?
Would you be able to share a larger snippet of your code, to get a better sense of what’s going on?
Just to cover all the bases, is [value of key] defined elsewhere in the code? Are you executing the query with the Query method from the AerospikeClient class, as well? Looking something (very simplified) like this:
client = new AerospikeClient("127.0.0.1", 3000);
var statement = new Statement();
statement.SetNamespace("core");
statement.SetSetName("zings");
statement.SetIndexName("i_zings_meta");
statement.SetBinNames("meta");
statement.SetFilter(Filter.Equal("meta", "[value of key]"));
record = client.Query(null, statement);
...and so on
What does the aql statement that returns look like?
Yes, statement is being called by following code block:
var recordSet = default(RecordSet);
try
{
// asyncClient is injected via a DI tool. No problem there as I am able to make other queries
recordSet = _asyncClient.Query(null, GetZingMetaStatement(mapKey));
while (recordSet.Next())
{
exists = true;
break;
}
}
finally
{
recordSet?.Close();
}
I am getting recordSet.Next() as false every time.
Following is the simplified structure of my set:
zid(string)|meta(map)
I have my index like: CREATE MAPKEYS INDEX i_zings_meta ON core.zings (meta) STRING
aql select * from core.zings in MAPKEYS where meta="https://www.youtube.com/watch?v=iFWD6rV0jFY" works good.
But code snippet is not working and I feel that my construction of Statement has some missing piece.
@aanderson you mentioned, “what does the returned aql statement look like?”. How do I grab the constructed aql statement?
In your aql you are using both lower and uppercase characters with your key, but in your code you are using .ToLower() (removing the uppercase characters). Can you try without the .ToLower()?