# How to search MAPKEY index

**URL:** <https://discuss.aerospike.com/t/how-to-search-mapkey-index/9229>\
**Category:** General Discussion\
**Tags:** query, secondary, index\
**Created:** [February 16, 2022, 9:50pm UTC](https://discuss.aerospike.com/t/how-to-search-mapkey-index/9229 "2022-02-16T21:50:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![pradeepgururani](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/pradeepgururani/32/1600_2.png) [@pradeepgururani](https://discuss.aerospike.com/u/pradeepgururani)\
**Post date:** [February 16, 2022, 9:50pm UTC](https://discuss.aerospike.com/t/how-to-search-mapkey-index/9229/1 "2022-02-16T21:50:59Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![aanderson](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/aanderson/32/2064_2.png) [@aanderson](https://discuss.aerospike.com/u/aanderson)\
**Post date:** [February 16, 2022, 11:15pm UTC](https://discuss.aerospike.com/t/how-to-search-mapkey-index/9229/2 "2022-02-16T23:15:35Z")

</div>

Hi @pradeepgururani, welcome to the community!

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](https://docs.aerospike.com/apidocs/csharp/html/M_Aerospike_Client_AerospikeClient_Query.htm) from the [AerospikeClient](https://docs.aerospike.com/apidocs/csharp/html/T_Aerospike_Client_AerospikeClient.htm) class, as well? Looking something (very simplified) like this:

```auto
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?

---

<div class="post-metadata">

**Author:** ![pradeepgururani](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/pradeepgururani/32/1600_2.png) [@pradeepgururani](https://discuss.aerospike.com/u/pradeepgururani)\
**Post date:** [February 16, 2022, 11:31pm UTC](https://discuss.aerospike.com/t/how-to-search-mapkey-index/9229/3 "2022-02-16T23:31:39Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![aanderson](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/aanderson/32/2064_2.png) [@aanderson](https://discuss.aerospike.com/u/aanderson)\
**Post date:** [February 16, 2022, 11:49pm UTC](https://discuss.aerospike.com/t/how-to-search-mapkey-index/9229/4 "2022-02-16T23:49:46Z")

</div>

Try switching your filter to `Filter.Contains("meta", MAPKEYS, "[value of key]")`

[Filter.Contains](https://docs.aerospike.com/apidocs/csharp/html/M_Aerospike_Client_Filter_Contains_1.htm) allows you to identify the index collection type, like you have in the aql statement.

---

<div class="post-metadata">

**Author:** ![pradeepgururani](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/pradeepgururani/32/1600_2.png) [@pradeepgururani](https://discuss.aerospike.com/u/pradeepgururani)\
**Post date:** [February 16, 2022, 11:57pm UTC](https://discuss.aerospike.com/t/how-to-search-mapkey-index/9229/5 "2022-02-16T23:57:54Z")

</div>

I updated the code, yet no luck.

```
 statement.SetFilter(Filter.Contains(ZingColumns.Meta, IndexCollectionType.MAPKEYS, metaKey.ToLower()));

```

Is there a way, I can see constructed aql by C# client?

---

<div class="post-metadata">

**Author:** ![aanderson](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/aanderson/32/2064_2.png) [@aanderson](https://discuss.aerospike.com/u/aanderson)\
**Post date:** [February 17, 2022, 1:27am UTC](https://discuss.aerospike.com/t/how-to-search-mapkey-index/9229/6 "2022-02-17T01:27:06Z")

</div>

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()?

---

<div class="post-metadata">

**Author:** ![pradeepgururani](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/pradeepgururani/32/1600_2.png) [@pradeepgururani](https://discuss.aerospike.com/u/pradeepgururani)\
**Post date:** [February 17, 2022, 6:27am UTC](https://discuss.aerospike.com/t/how-to-search-mapkey-index/9229/7 "2022-02-17T06:27:04Z")

</div>

Thanks you very much @aanderson. That was such a silly mistake on my end.

After removing `.ToLower()`, `Filter.Equal` is also working fine.

Thank you once again.

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/system/32/2274_2.png) [@system](https://discuss.aerospike.com/u/system)\
**Post date:** [May 12, 2022, 6:27am UTC](https://discuss.aerospike.com/t/how-to-search-mapkey-index/9229/8 "2022-05-12T06:27:29Z")

</div>

This topic was automatically closed 84 days after the last reply. New replies are no longer allowed.
