Reputation: 29713
I am running into a very basic problem of querying my data from the Datastore Viewer console based on a simple WHERE <column> = 'xxx'
type query.
Here is a snapshot of my dummy data:
From what I understand, I should be able to query for that record based on the "email" field, or any other field, using SELECT * FROM User WHERE email = 'a'
. But that returns "No results in Empty namespace." as can be seen below:
I don't see what is different to the situation in this related question:
I have examined that record in the Entity editor, and can confirm that the value of the email field is "a", without any extra hidden spaces:
Mihail suggested that I need to create an index for this query.
Following the Java Datastore Index Configuration docs, I created the file datastore-indexes.xml
in /war/WEB-INF:
<?xml version="1.0" encoding="utf-8"?>
<datastore-indexes autoGenerate="false">
<datastore-index kind="User" ancestor="false">
<property name="email" direction="asc" />
</datastore-index>
</datastore-indexes>
I was unable to deploy my project because it did not allow this index to be uploaded. The error message I got was:
Creating a composite index failed for entity_type: "User"ancestor: falseProperty { name: "email" direction: 1}: This index:entity_type: "User"ancestor: falseProperty { name: "email" direction: 1}is not necessary, since single-property indicies are built in. Please remove it from your index file and upgrade to the latest version of the SDK, if you haven't already.
Upvotes: 1
Views: 1379
Reputation: 2536
It sounds like the email
property is not indexed and you can't do any queries on unindexed properties, even as simple as this one, because if you had, say million users, this query would have to fetch all million entities to find the ones you need.
All you need to do is make the email
property indexed but note that it will not take care of past entities. You are going to need to re-save all past entities in order for the new index to be applied.
To make a property indexed:
In Objectify the @Index
annotation needs to be added to the property. More details here.
If using low-level Java Datastore API make sure to define the property with setProperty()
and not with setUnindexedProperty()
. More details here.
If using Python's NDB, make sure indexed
attribute is not set to False
since most properties are indexed by default. More details here.
Upvotes: 2