Search code examples
gonosqlaerospike

Reverse mapping in aerospike


I have a few records in aerospike in following key-value pair :

Key : "1234" 
Value : {
            "XYZ":{
                "B":[1,3]
                "C":[3,4]
            }
        }

Key : "5678" 
Value : {
            "XYZ":{
                "B":[1,3,5]
                "C":[3,4]
            }
        }

I want to get all the keys from set where field "B" in json value contains let say 3. Is there any way to query all such keys in golang ?


Solution

  • Yes, you can build a secondary index on the values in map key "B" ... at that nested level and then run a secondary index query to get all matching records.

    You can do the same in Go using equivalent APIs.

    Many Java interactive code examples at: https://developer.aerospike.com/tutorials/java/cdt_indexing

    For example, this is top level example with string values:enter image description here

    Then another example where you can build a SI on nested sublevel: enter image description here