I am getting this error when inserting data into a...
# community-help
b
I am getting this error when inserting data into a self hosted typesense v0.27.0, i do send in updated/at here.
Copy code
Error: "Field `<http://updated.at|updated.at>` has been declared in the schema, but is not found in the document.",
    Document: "{\"contract\":{\"name\":\"egg\",\"symbol\":\"EGG\",\"address\":\"0x51bb4c8bb4901d6AA061282cd7Ed916eEc715a29\",\"network\":\"ethereum\"},\"owner\":\"0xcf851420E8838f89FBda2b392504A81d3B7d5514\",\"status\":\"Active\",\"description\":\"Luigi's uncommon egg is bubbling with cosmic energy. It offers the texture of the stars, and if rubbed vigorously, its power might just glitch your reality.\",\"image\":\"<ipfs://bafybeie2c6iza4grgt4oey4ikes3atxjrixvluy3c34jcx5wx3ojjpmvk4/1>\",\"token_uri\":\"<ipfs://bafybeigeka2kygtdometxgsyok6jgfupc3cpqx2oha5sudvmloxsykkihy/1>\",\"id\":\"ethereum-0x51bb4c8bb4901d6AA061282cd7Ed916eEc715a29-1\",\"group\":\"egg\",\"nft_id\":\"1\",\"name\":\"egg\",\"attributes\":[{\"trait_type\":\"tier\",\"string_value\":\"Uncommon\"}],\"updated\":{\"transaction\":\"0xec7f2f75948f5870ee69fd09394d7534a873edab9f0746d50288dec5ebc6bc69\",\"at\":\"2024-10-16 12:34:35 +0000 UTC\",\"timestamp\":1729082075,\"height\":20978152}}",
see schema
if i remove index=false then it works
f
<http://updated.at|updated.at>
is expected to be flattened when passed into the document. Basically everything that's not under an
object
field, is flattened in this case, as you don't specify that
rarities
or
updated
are object fields and their nested children are
rarities.max
<http://updated.at|updated.at>
etc. Typesense will automatically infer the structure of the
updated
object you pass, but will not associate it with the fields you've explicitly defined as
<http://updated.at|updated.at>
. What you'd need to do is have a
updated
field with a type of
object
or
object[]
depending on your use-case, and then define all of them under it
b
ok
ok, so an extra field in the schema for the object or object[]?
f
I simply added
{type: object, name: updated}
as an extra field in your schema and then imported the document as:
Copy code
❯ curl -X POST "<http://localhost:8108/collections/nft2/documents>" \
     -H "Content-Type: application/json" \
     -H "X-TYPESENSE-API-KEY: xyz" \
     -d '{
  "contract": {
    "name": "egg",
    "symbol": "EGG",
    "address": "0x51bb4c8bb4901d6AA061282cd7Ed916eEc715a29",
    "network": "ethereum"
  },
  "owner": "0xcf851420E8838f89FBda2b392504A81d3B7d5514",
  "status": "Active",
  "description": "Luigis uncommon egg is bubbling with cosmic energy. It offers the texture of the stars, and if rubbed vigorously, its power might just glitch your reality.",
  "image": "<ipfs://bafybeie2c6iza4grgt4oey4ikes3atxjrixvluy3c34jcx5wx3ojjpmvk4/1>",
  "token_uri": "<ipfs://bafybeigeka2kygtdometxgsyok6jgfupc3cpqx2oha5sudvmloxsykkihy/1>",
  "id": "ethereum-0x51bb4c8bb4901d6AA061282cd7Ed916eEc715a29-1",
  "group": "egg",
  "nft_id": "1",
  "name": "egg",
  "attributes": [
    {
      "trait_type": "tier",
      "string_value": "Uncommon"
    }
  ],
  "updated": {
    "transaction": "0xec7f2f75948f5870ee69fd09394d7534a873edab9f0746d50288dec5ebc6bc69",
    "at": "2024-10-16 12:34:35 +0000 UTC",
    "timestamp": 1729082075,
    "height": 20978152
  }
}'
{"attributes":[{"string_value":"Uncommon","trait_type":"tier"}],"contract":{"address":"0x51bb4c8bb4901d6AA061282cd7Ed916eEc715a29","name":"egg","network":"ethereum","symbol":"EGG"},"description":"Luigis uncommon egg is bubbling with cosmic energy. It offers the texture of the stars, and if rubbed vigorously, its power might just glitch your reality.","group":"egg","id":"ethereum-0x51bb4c8bb4901d6AA061282cd7Ed916eEc715a29-1","image":"<ipfs://bafybeie2c6iza4grgt4oey4ikes3atxjrixvluy3c34jcx5wx3ojjpmvk4/1>","name":"egg","nft_id":"1","owner":"0xcf851420E8838f89FBda2b392504A81d3B7d5514","status":"Active","token_uri":"<ipfs://bafybeigeka2kygtdometxgsyok6jgfupc3cpqx2oha5sudvmloxsykkihy/1>","updated":{"at":"2024-10-16 12:34:35 +0000 UTC","height":20978152,"timestamp":1729082075,"transaction":"0xec7f2f75948f5870ee69fd09394d7534a873edab9f0746d50288dec5ebc6bc69"}}%
b
thanks, will try
❤️ 1
and thank you for your prompt reply!
🙌 1
Copy code
{
      "name": "royalties",
      "type": "object[]",
      "optional": true
    },
    {
      "name": "royalties.address",
      "type": "string[]",
      "facet": true
    },
    {
      "name": "royalties.cut",
      "type": "float[]",
      "facet": true
    },
    {
      "name": "royalties.description",
      "type": "string[]",
      "facet": false,
      "index": false,
      "optional": true
    },
i get this error now panic: Field
royalties.address
has been declared in the schema, but is not found in the document.
royalties here is empty
and the object[] is nil empty
so the intent here is a list of objects that each have the field address/cut/dscription
if i add optionals to the items in there it seems to work
f
Yeah
royalties
wasn't present in the document you posted earlier:
Copy code
{
  "contract": {
    "name": "egg",
    "symbol": "EGG",
    "address": "0x51bb4c8bb4901d6AA061282cd7Ed916eEc715a29",
    "network": "ethereum"
  },
  "owner": "0xcf851420E8838f89FBda2b392504A81d3B7d5514",
  "status": "Active",
  "description": "Luigi's uncommon egg is bubbling with cosmic energy. It offers the texture of the stars, and if rubbed vigorously, its power might just glitch your reality.",
  "image": "<ipfs://bafybeie2c6iza4grgt4oey4ikes3atxjrixvluy3c34jcx5wx3ojjpmvk4/1>",
  "token_uri": "<ipfs://bafybeigeka2kygtdometxgsyok6jgfupc3cpqx2oha5sudvmloxsykkihy/1>",
  "id": "ethereum-0x51bb4c8bb4901d6AA061282cd7Ed916eEc715a29-1",
  "group": "egg",
  "nft_id": "1",
  "name": "egg",
  "attributes": [
    {
      "trait_type": "tier",
      "string_value": "Uncommon"
    }
  ],
  "updated": {
    "transaction": "0xec7f2f75948f5870ee69fd09394d7534a873edab9f0746d50288dec5ebc6bc69",
    "at": "2024-10-16 12:34:35 +0000 UTC",
    "timestamp": 1729082075,
    "height": 20978152
  }
}
b
no this particular instance does not have it
but what i am trying to model is that if this item has royalties then the address field must be set
so the object[] is optional
f
Yeah, it's optional then!
b
ok
f
but what i am trying to model is that if this item has royalties then the address field must be set
That kind of business logic isn't available in Typesense, you'd want to use an external schema validator library for this purpose before sending the data out to Typesense. If you're using Typescript / Javascript, you can check out zod. For python there's pydantic
b
i am using golang, and it is fine. i trust all import sources