Problems with the GQL query, Google Data Warehouse. Error under several conditions and higher than operators

I am trying to query Datastore and my query looks like this:

SELECT * FROM mydb WHERE Latitude = "18.1" AND Number > "1" 

However, this does not work. I get this error in the Datastore request window:

GQL query error: your data warehouse does not have a composite index (supplied by the developer) for this query.

And this error when running my code:

no matching match index found. Recommended index: \ n- view: mydb \ n properties: \ n - name: Location \ n - name: Number \ n

Simple queries like this one work:

 SELECT * FROM mydb WHERE Number > "1" AND Number < "5" 

I can access only one column, maybe that's why?

Not,

Then I tried the query as follows:

 SELECT * FROM mydb WHERE Latitude = "18.1" AND Number = "1" 

It worked.

I tried to find a solution and I came across this page: https://cloud.google.com/datastore/docs/tools/indexconfig#Datastore_About_index_yaml

After going through this page, I realized that I needed the index.yaml file. It is assumed that it is located in the WEB-INF folder. But I do not have this folder.

This is a small piece of my code:

 Query<Entity> query = Query .gqlQueryBuilder(Query.ResultType.ENTITY, "SELECT * FROM " + kind + " WHERE Location = @location AND Number <= @number") .setBinding("number", "5").setBinding("location", "18.1").build(); QueryResults<Entity> results = datastore.run(query); 
+6
source share
1 answer

The error you get is that the requested query requires Composite indexes , which are not available by default, They must be specified within index.yaml .

Article Creating index files , which is slightly different from the published one, especially for Java applications running in a flexible environment.

There are two ways to create index.yaml :

  • Manually use your favorite text editor according to the rules and structure as indicated in Index Definitions .
  • Generate a file during local testing. This can be done using the gcloud beta emulators datastore start command. You can also use the --data-dir <dir> option to indicate where the generated index.yaml should be written.

Then, if you have index.yaml and the same directory as app.yaml , you can deploy it using the gcloud preview app deploy index.yaml from that directory. This process is briefly described in Deploying an Index File .

I also recommend reading Organizing yaml configuration files .

+2
source

All Articles