Hey guys! I'm trying to create a schema for a coll...
# community-help
m
Hey guys! I'm trying to create a schema for a collection in Typesense cloud server, we're sending this payload
Copy code
schema = {
  'name': 'appointments_development',
  'default_sorting_field': 'arrival_time',
  'fields': [
    { 'name': 'id', 'type': 'string' },
    { 'name': 'shipper_id', 'type': 'string', facet: true },
    { 'name': 'facility_id', 'type': 'string', facet: true },
    { 'name': 'confirmation_id', 'type': 'string', facet: true },
    { 'name': 'facility_name', 'type': 'string', facet: true },
    { 'name': 'dock_id', 'type': 'string' },
    { 'name': 'dock_name', 'type': 'string', facet: true },
    { 'name': 'equipment_type_id', 'type': 'string', facet: true },
    { 'name': 'appointment_type_id', 'type': 'string', facet: true },
    { 'name': 'appointment_type_name', 'type': 'string', facet: true },
    { 'name': 'status', 'type': 'string', facet: true },
    { 'name': 'created_by_id', 'type': 'string' },
    { 'name': 'created_by_name', 'type': 'string', facet: true },
    { 'name': 'scheduler_id', 'type': 'string' },
    { 'name': 'scheduler_name', 'type': 'string', facet: true },
    { 'name': 'checkin_id', 'type': 'string' },
    { 'name': 'checkin_status', 'type': 'string', facet: true },
    { 'name': 'commodity_type', 'type': 'string', facet: true },
    { 'name': 'less_than_truckload', 'type': 'bool', facet: true },
    { 'name': 'repeating', 'type': 'bool', facet: true },
    { 'name': 'purchase_order_identifiers', 'type': 'string[]' },
    { 'name': 'answer_identifiers', 'type': 'string[]' },
    { 'name': 'has_attachments', 'type': 'bool' },
    { 'name': 'color', 'type': 'string' },
    { 'name': 'arrival_time', 'type': 'int64', facet: true },
    { 'name': 'time_zone', 'type': 'string' },
    { 'name': 'created_at', 'type': 'int64' }
  ]
}
But we noticed the ID field is not being created and we do not understand why as we haven't edit this schema in a while and we were able to create collection with it in the past
j
But we noticed the ID field is not being created
Are you referring to the ID field not showing when you view the schema after creating it?
m
Correct, we cannot view it or sort by it
If we try to manually add it, we get this error
j
The
id
field in Typesense has always been a special field we also used internally to deduplicate documents, and it had to be a string type. So it was never really configurable using the schema and it led to confusion. So in the latest version of Typesense 0.24 (and also in 0.23 IIRC), we essentially disregard the
id
field and don’t allow searching / sorting on it, since it has additional implications internally. So if you need to do other operations on that field, you want to create a new string field in the collection, store the attribute there and then sort / facet on it as needed
m
Got it, I started doing this migration to a new field we called
vslot_id
, I was trying to delete with a filter_by endpoint but I get this error: `error_message":"undefined method
delete' for <Typesense::Documents:0x0000562b305cbb40>
We're using the Ruby client with version typesense (0.14.1, 0.13.0, 0.8.0)
This is the statement that fails:
Copy code
TypesenseClient.fetch.collections[klass.index_name].documents.delete(filter_by: "vslot_id:=#{id}")
I wonder if maybe we're using the wrong version
I already did all the changes to the schema and re index all the info, verified in Typensense Cloud but now in my project I want to change some actions we have for example the delete that was working like this before:
Copy code
TypesenseClient.fetch.collections[klass.index_name].documents[id].delete
Maybe we need to update to v0.17.0 at least, but I see the gem just gets until v0.14.1
j
0.14.1 does have the delete by query option…
Let me double-check
Could you share with me a standalone ruby script that i can run locally, to replicate the error?
Similar to this script
m
Sure, we basically set up the client and then execute a statement like the one you just send me:
Copy code
class TypesenseClient
  def self.fetch
    @client = Typesense::Client.new(
      nodes: [{
        host: ENV['TYPESENSE_HOST'],
        port: 443,
        protocol: 'https'
      }],
      api_key: ENV['TYPESENSE_API_KEY'],
      connection_timeout_seconds: 2
    )

    @client
  end
end

TypesenseClient.fetch.collections['appointments'].documents.delete(filter_by: "vslot_id:=#{id}")
j
Could you run the script I shared, in your app?
It basically creates a collection, adds a few docs and tries to delete it
m
I just executed but it failed in a different line than I expected: https://github.com/typesense/typesense-ruby/blob/c0e7173b202371cd6cd32f0054b79dbfdbbe5681/examples/collections_and_documents.rb#L189 Saying:
Copy code
web     | {
web     |      "company_name" => "Stark Industries",
web     |           "country" => "USA",
web     |                "id" => "124",
web     |     "num_employees" => 5215
web     | }
web     |   
web     | Typesense::Error::RequestMalformed (The `id` of the resource does not match the `id` in the JSON body.):
(Removed the id line)
m
Got it! I just executed it and this was the error:
Copy code
NoMethodError (undefined method `delete' for #<Typesense::Documents:0x000055b307742f60>):
In this line: https://github.com/typesense/typesense-ruby/blob/c0e7173b202371cd6cd32f0054b79dbfdbbe5681/examples/collections_and_documents.rb#L262
j
That script works for me as expected on my machine. Notice the corresponding output
Could you double check that you’re not using an old version of the typesense gem, may be in some stale bundler cache for eg
m
Taking a look at the logs they seemed correct but if we look at Typesense we noticed that the update and delete calls, never worked: 1. The document with id '124' still exists. Hence, it was not deleted 2. The document with id '124' still shows 5215 as num_of_employees instead of 5500. Hence, it was not updated
j
I ran that script on my local Typesense node btw, not against your cluster
m
Yes, but I ran it against my cluster and we got the result described above
This all started because we have a delete process done by ID and it stopped working
And with this test we noticed that the delete by document ID and update by document ID did no effect in the collection records
Would it be possible to have a meeting with you Jason?
j
I’ll DM you