The database services on cloud are appearing as an attractive way of outsourcing databases. When a database is deployed on a cloud database service, the data security and privacy becomes a big concern for users. A straightforward way to address this concern is to encrypt the database. However, after encryption, the database cannot be easily queried. In this paper, we propose a nonlinear order preserving scheme for indexing encrypted data, which facilitates the range queries over encrypted databases. The scheme is secure even there are a large number of duplicates in plaintexts. Moreover, our scheme allows the programmability of basic indexing expressions and thus provides the capability of hiding the distribution of plaintexts from the distribution of indexes. This scheme is suitable for long-standing databases because its use does not need any assumption on the characteristics of database data, such as their distribution, range and number, which may change dramatically over time.Copyright © 2013 John Wiley & Sons, Ltd.