Hey. We would like to add some more fields to our ...
# community-help
a
Hey. We would like to add some more fields to our items in typesense. We also want these fields indexed. Our typesense server is running in production, so we don’t wanna wipe all data to make this change. Is it possible to add new fields (indexed ) to the schema and our items on the fly?
From what i can read from similar asked question, we have to make a new collection, is that the only way? This means, we must upgrade our Typesense Cloud memory to do this. We would like to have no downtime for this change.
k
👋 @Alex Lööf We don't have a way to modify the schema at the moment but that's on our backlog. You can just create a new collection and swap to it. The Collection Alias features makes this really easy to do without updating your app configuration: https://typesense.org/docs/0.20.0/api/collection-alias.html
For now, if your cluster is also not having enough memory, then you have to index on another cluster and swap over. For future use: you can use automatic schema detection to help with schema changes. For e.g you can have a collection with a field defined as: `
Copy code
{
  "name": ".*_int32",
  "type": "int32"
}
This way, you can easily add a new field called
age_int32
and this will be automatically be inferred and indexed by Typesense.
Automatic schema detection is available on
v0.20.0
a
Thanks Kishore! Do you see any downsides to adding:
Copy code
{"name": ".*", "type": "auto" },
{"name": ".*_facet", "type": "auto", "facet": true }
to our schema? To make sure we never have to swap clusters again.
k
The only downside is that every field present in the document will be indexed. Using something like
.*_int32
gives you flexibility. If you have two integer fields only one of which must be indexed, then suffix the indexable field name with
_int32
but for the other field name don't do that, so it is only stored and not indexed.
1