What is the best way for storing and retrieving Json data?.I need to store json request object which will have variable fields (eg name,age,gender) and later query on it (eg.where gender=male). I am new to aerospike. Any help would be appreciated.
Query by value can be done on bins. In this case, a record should have bins called “name”, “age”, “gender”, and a secondary Index created on the bin “gender”.
When trying to work on something as generic as “gender” where half of the database will be returned, consider also doing a database scan(). This will avoid lock contentions on insert/query of the records due to the bi-modalness of the value.
Some more options that you could consider.
Storing each field in the json document as different bin in aerospike (as explained in the answer before)
If you want to keep the json document in tact
If you know the field which you want to query on and if they are limited in number, you can serialize the json doc and store in one bin. But also save the fileds that you are interested to query on later in seperate bins and build a secondary index on them.
Aerospike is about to support secondary indexes on list and maps. Once this feature is available, you can convert the json doc into a map and store in a single bin aerospike. You can convert the map to json back. To convert json to/from map in java, there are libraries available (like google gson or jackson: link1, link2)