# How to create secondary index on multiple fields (composite key)

**URL:** https://discuss.aerospike.com/t/how-to-create-secondary-index-on-multiple-fields-composite-key/8891
**Category:** Operations
**Created:** [October 7, 2021, 9:08am UTC](https://discuss.aerospike.com/t/how-to-create-secondary-index-on-multiple-fields-composite-key/8891 "2021-10-07T09:08:23Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Jitendra](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@Jitendra](https://discuss.aerospike.com/u/Jitendra)
#### Post date: [October 7, 2021, 9:08am UTC](https://discuss.aerospike.com/t/how-to-create-secondary-index-on-multiple-fields-composite-key/8891/1 "2021-10-07T09:08:23Z")

</div>

we want to create a secondary index on 3 fields in a set. The goal is to query the data using these 3 fields. We are using Spring Data Aerospike. Please suggest appropriate solution.

---

<div class="post-metadata">

### Author: ![neelp](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/neelp/32/1369_2.png) [@neelp](https://discuss.aerospike.com/u/neelp)
#### Post date: [October 10, 2021, 6:48pm UTC](https://discuss.aerospike.com/t/how-to-create-secondary-index-on-multiple-fields-composite-key/8891/2 "2021-10-10T18:48:46Z")

</div>

In Aerospike, a secondary index is built on a single field, but you can separately create a secondary index on multiple fields. A query requires and uses a secondary index only on the field of the query predicate. Multiple secondary indexes in the namespace can be useful if you query the records separately using different queries, each using its own secondary index. If your filter has multiple fields, use the most selective (ie, that returns fewest records) portion of the predicate as the query predicate, and specify the remaining portion as a filter expression in the policy. (Hope this helps as I am assuming these abstractions are accessible through Spring Data Aerospike,)

---

<div class="post-metadata">

### Author: ![Jitendra](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@Jitendra](https://discuss.aerospike.com/u/Jitendra)
#### Post date: [October 18, 2021, 8:11am UTC](https://discuss.aerospike.com/t/how-to-create-secondary-index-on-multiple-fields-composite-key/8891/3 "2021-10-18T08:11:37Z")

</div>

Thank you Neel. This helps. Yes, we are using Spring Data Aerospike. And apologies for delayed reply (I was on vacation).

Jitendra

---

<div class="post-metadata">

### Author: ![Jitendra](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@Jitendra](https://discuss.aerospike.com/u/Jitendra)
#### Post date: [October 18, 2021, 10:58am UTC](https://discuss.aerospike.com/t/how-to-create-secondary-index-on-multiple-fields-composite-key/8891/4 "2021-10-18T10:58:25Z")

</div>

Neel,

It appears that filter expressions is supported in Spring Data Aerospike v3.2.0, released 20 days ago. I don’t find example on how to use it. Will be great if there is some documentation/example around using filter expressions with Spring Data Aerospike.

Thanks Jitendra

---

<div class="post-metadata">

### Author: ![neelp](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/neelp/32/1369_2.png) [@neelp](https://discuss.aerospike.com/u/neelp)
#### Post date: [October 18, 2021, 3:53pm UTC](https://discuss.aerospike.com/t/how-to-create-secondary-index-on-multiple-fields-composite-key/8891/5 "2021-10-18T15:53:20Z")

</div>

You can find a tutorial with examples and pointers to other content on Filter Expressions on the Developer Hub [here](https://developer.aerospike.com/docs/tutorials/java/expressions).

---

<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: [October 18, 2022, 3:53pm UTC](https://discuss.aerospike.com/t/how-to-create-secondary-index-on-multiple-fields-composite-key/8891/6 "2022-10-18T15:53:55Z")

</div>

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