0
votes

It seems that in development App Engine server datastore-indexes.xml doesn't work. Is it true? Also, I created a datastore-indexes.xml file with autoGenerate="true" but it didn't generate me any indexes in datastore-indexes-auto.xml. Why?

<?xml version="1.0" encoding="utf-8"?>
<datastore-indexes autoGenerate="true">
    <datastore-index kind="UserData" ancestor="false">
        <property name="email" direction="asc" />
        <property name="email" direction="desc" />
        <property name="lastName" direction="asc" />
        <property name="lastName" direction="desc" />
    </datastore-index>
</datastore-indexes>

UPDATED

There is my entity:

@Entity
@Index
public class UserData implements PersistableObject {

    @Id
    Long id;

    String email;
    String firstName;
    String lastName;
    String middleName;
    String passwordHash;
    UserType userType;
}

There is my Dao:

public class UserDataDao {
    public List<UserData> getUsers(int startRow, int limit, String columnName, boolean ascending) {
        Query<UserData> query = ofy().load().type(UserData.class)
                .offset(startRow).limit(limit);
        if (columnName != null) {
            query.order((ascending ? "" : "-") + columnName);
        }
        return query.list();
    }

    public int usersCount() {
        return ofy().load().type(UserData.class).count();
    }

    public UserData find(Class<? extends UserData> aClass, Long userId) {
        return ofy().load().type(aClass).id(userId).now();
    }
}

Queries are being executed but indexes haven't created even if I leave only datastore-indexs tag.

1
Did you run queries in your devserver? - Patrice
Yes, but I use Objectify. - Alex Po
That shouldn't change anything. If you have autogenerate set to true, the system should create all required indexes as you run queries... - Patrice
But it does. Any other idea? - Alex Po
Alex that index doesn't make any sense, please elaborate on the queries you are running, my guess is neither needs additional indexes. - jirungaray

1 Answers

0
votes

Additional indexes are not being created because you are only querying on single attributes. Those indexes are automatically created when you @Index an attribute.

Additional indexes will be required on complex queries involving multiple attributes (both filtering and sorting).

Tip: It's really a bad idea to index all fields on an entity, this will add several writes required to store every entity and that will raise your app costs FAST, consider only indexing the field you plan to filter,sort on