简体   繁体   中英

Query Google Cloud Datastore to retrieve matching results

I am using Google Cloud Datastore to save my application data. I have to add a query to get all results matching with Name, Brand or Sku.

Query data with one of the field is returning me records but using all fields together returns me error.

Query:

  const term = "My Red";
  const q = gstore.createQuery(req.params.orgId, "Variant")
  .filter('brand', '=', term)
  .filter('sku', '=', term)
  .limit(10);

Error:

{"msec":435.96913800016046,"error":"no matching index found. recommended index is:
- kind: Variant
properties:
- name: brand
- name: sku
","data":{"code":412,"metadata":{"_internal_repr":{}},"isBoom":true,"isServer":true,"data":null,"output":{"statusCode":500,"payload":{"statusCode":500,"error":"Internal Server Error","message":"An internal server error occurred"},"headers":{}}}} Debug: internal, error

Also, I want to perform OR operation to get matching results as above will return data with AND operation. Please help me to find correct path to achieve the desired result.

Thanks in advance and let me know if something is not clear.

The error indicates that the composite index required by the respective query is not in Serving state.

That means it's either not created/deployed or it was recently deployed and is still being built.

Composite indexes must be specifically created and deployed in your app.

If you didn't create it you need to do so. The error message indicates the content the index configuration requires. If you're using the development server it might create it automatically, but you still need to deploy it.

See Indexes docs for more details.

If you recently deployed the composite index please note that it can take some significant amount of time until the matching index is built, depending on how many entities of that kind already exist in the Datastore. You can check the status of the index building in the developer console, on the Indexes page

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM