question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't store entities with embedded entities which have properties > 1500 bytes

See original GitHub issue

Seems that excluding a top level property doesn’t exclude an embedded entities properties from being indexed - on top of that, I don’t believe there’s a way to exclude an embedded entities individual properties, that would solve my problem too.

Steps to reproduce

Just use this script (I’m running the datastore emulator)

const Datastore = require('@google-cloud/datastore');
const datastore = new Datastore({ projectId: 'datastore-test' });

datastore.insert({
  key: datastore.key('User'),
  data: [
    {
      name: 'description',
      value: {
        text: Buffer.alloc(1501, 'a').toString(),
      },
      excludeFromIndexes: true
    }
  ]
}, (err, result) => {
  if (err) {
    console.error(err);
  } else {
    console.log(result.data);
  }
});

I’d expect there to be no error - the embedded entity ({ text: '...' }) shouldn’t be indexed I believe? But it throw an error saying:

Error: The value of property "text" is longer than 1500 bytes.

Environment

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:41 (18 by maintainers)

github_iconTop GitHub Comments

14reactions
ggprodcommented, Jun 5, 2017

Could I ask what the status of this issue is? I have some entities that have embedded entities that have properties that are >1500 Bytes. When I try setting excludeFromIndexes: true on the embedded entity I still get an error thrown for its sub-properties that are >1500 Bytes. Is there some way I can store them?

3reactions
bedeoverendcommented, Jan 26, 2017

@stephenplusplus thanks for the options - I think the data seems to make the more sense to me… i.e. value is for more ‘basic’ types, and data for embedded objects.

It’s pretty fringe edge case at this point - and I’m not sure if it’s even possible to do, but if you had an array of objects, could you index them?

e.g.

var rawPersonEntity = {
  key: datastore.key('Person'),
  data: [
    {
      name: 'name',
      value: 'Mary'
    },
    {
      name: 'metadata',
      data: [
        {
          excludeFromIndexes: true,
          name: 'bio',
          value: '...'
        }
      ]
    },
    {
      name: 'subjects',
      value: [
        {
          excludeFromIndexes: true, // Is this something that can be done? Is there a reason why it would be done?
          name: 'history',
          credits: 2
        },
        // ...
      ]
    }
  ]
}

Other than that, I can’t see any issue with them…Another option would be making an datastore.value style factory - like datastore.key - where you can specify types and the data associated with it e.g.

datastore.insert({
  key: datastore.key('Person'),
  data: datastore.value({
    type: datastore.Entity, // Defaults to 'auto'
    data: {
      name: datastore.value({
        type: String,
        value: 'Mary'
      }),
      metadata: datastore.value({
        type: datastore.Entity,
        value: {
          bio: datastore.value({
            type: String,
            excludeFromIndexes: true,
            value: '...'
          })
        }
      }),
      subjects: datastore.value({
        type: Array,
        value: [
          datastore.value({
            type: datastore.Entity,
            value: {
              name: datastore.value({
                type: String,
                value: 'history',
              }),
              credits: datastore.value({
                type: Number,
                value: 2
              })
            }
          },
          datastore.value({
            type: datastore.Entity,
            value: {
              name: datastore.value({
                type: String,
                value: 'french',
              }),
              credits: datastore.value({
                type: Number,
                value: 4
              })
            }
          },
          datastore.value({
            type: datastore.Entity,
            value: {
              name: datastore.value({
                type: String,
                value: 'maths',
              }),
              credits: datastore.value({
                type: Number,
                value: 4
              })
            }
          }
        ]
      })
    }
  });

Ha - after writing that all out, I realise how incredibly over the top that looks, but it feels robust. Perhaps not as a candidate for quickly writing out simple entities, but perhaps as a way that will work well with a helper utility? e.g. for my use case, I’m converting incoming JSON to an entity, and I want to recursively step through it and add excludeFromIndexes as needed…thoughts?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google Datastore 1500 byte property limit for embedded entities
I am trying to write an embedded entity that has some properties that are longer than 1500 bytes and I'm getting an error:....
Read more >
Entities, Properties, and Keys | Cloud Datastore Documentation
Data objects in Firestore in Datastore mode are known as entities. An entity has one or more named properties, each of which can...
Read more >
Model and Property — ndb documentation - Google Cloud
A model class represents the structure of entities stored in the datastore. ... property is indexed but the value exceeds the maximum length...
Read more >
Hibernate Search 6.0.10.Final: Migration Guide from 5.11
If you need both a Lucene backend and an Elasticsearch backend, proceed as follows: Annotate entities that must be indexed in the ...
Read more >
datastore package - github.com/derivita/fsdatastore - Go Packages
The Get and Put functions load and save an entity's contents. ... than 1500 bytes cannot be indexed; fields used to store long...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found