Repository navigation
Is datastore.createQuery.hasAncestor() just work alone without any other query command like order sort or select? #803
Description
Activity
Thanks for reporting! I'm not sure in this case, but I bet @pcostell can help.
- addedtype: questionRequest for information or clarification. Not an issue.Request for information or clarification. Not an issue.api: datastoreIssues related to the Datastore API.Issues related to the Datastore API.
on Aug 17, 2015 In order to use
hasAncestorwith an order you'll need to build an index. If you try running that query while using the gcd.sh tool, it should recommend the proper index. You can learn more about the index config and gcd tool indexes and the gcd tool in general.In this particular case, your datastore-indexes.xml file should look something like:
<?xml version="1.0" encoding="utf-8"?> <datastore-indexes autoGenerate="true"> <datastore-index kind="table" ancestor="true"> <property name="time" direction="desc" /> </datastore-index> </datastore-indexes>Hi Pcostell,
Thank you so much for quickly reply.
I got it.
You are right, I did not ready the indexes.xml file.
The Datastore is so magical, different than SQL. I like that idea to storage data.
ALso thank you Stephenplusplus.
PeterHI,
I try add a indexes.xml for my project, Because I use the Goole App with Node.js, so It looks hard to add a indexes.xml file to application's dataset directory. Because if you use gcloud command to push to remote. I try add the Index.xml in my local node project's directory like /war/WEB-INF/appengine-generated/datastore-indexes.xml, then push to remote. Finally it looks not working.
So it looks just one way that is use the gcd tool.- Download gcd-v1beta2-rev1-2.1.1.zip
- #unzip gcd-v1beta2-rev1-2.1.1.zip <------ use terminal command, if not you will get 'appengine-tools-api.jar not found' ERROR
- #gcd.sh create -d my-dataset my-project <---- use gcd command to create local dadastore
- Than you can check the directory my-project/WEB-INF/ have some file
- Add your index file to that WEB-INF/datastore-indexes.xml
- #gcd.sh updateindexes --auth_mode=oauth2 my-project <--- then push local datastore setup to remote project
- open Developers console web page. check the indexed at Storage->Cloud Datastore->Indexes. It show a index detail.
Then all looks fine.
My problem looks clear.
My question is why let us do so hard work for add a index. (SQL don't need do).
May be make a 'New index' on Developers console's Datastore.Indexes. You can edit or create a new index with webpage, because some case we don't use Python or Java.I very love use Datastore and need clean up all my SQL idea. I hope it will easy to use and learn.
@petersunquest sorry it's not super easy right now. We are working to integrate gcd into the gcloud command line tool, which will make this much nicer. In the future we also plan to make index creation available via an API, so you should get the "New Index" option in the developer console.
Unlike SQL, Datastore requires that all queries scale with the size of the result set. Because of this, specific indexes are required to actually run a query. For example, if you were filtering for
x = 2, but had no indexes and billions of entities, you would need to scan every single entity looking for entities that match that filter. With Datastore, we require an index onxso that all the results for your queryx = 2exist in a single range scan of the index. Note that if you were running SQL this is still a real concern (which is why you can build indexes), SQL is just willing to issue the expensive (time and cost) query to get your results.- added a commit that references this issue
on Nov 10, 2022 - added a commit that references this issue
on Jul 23, 2025 - added a commit that references this issue
on Feb 3, 2026 - added a commit that references this issue
on Mar 12, 2026 - added a commit that references this issue
on Mar 18, 2026 - added 2 commits that reference this issue
on Mar 23, 2026 - added a commit that references this issue
on Mar 27, 2026 - added a commit that references this issue
on May 5, 2026
Hi,
I use the [email protected] & nodejs 0.12.7.
And use datastore.createQuery get some result.
Every looks great when I do a query with filter + sort + select + limit + order same time.
But I got Error 412 'Precondition Failed' when I add a hasAncestor() for any filter + sort + select + limit. Even I change order for each one when createQuery.
I used hasAncestor() whthout other filter or sort was work fine.
Is the hasAncestor() can only alone, can't use other command as sort or select or filter same time?
Or that is a bug?
I did:
var q = ds.createQuery('table')
.hasAncestor(ds.key({path:['fatherTable','fatherName']}))
.select('time')
.order('-time')
.limit(5)