typesense / typesense

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚑ πŸ” ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Home Page:https://typesense.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When updating a collection schema, with `{sort: true, type: auto}` an error is returned, but field is still added to the schema

jasonbosco opened this issue Β· comments

Steps to reproduce

export TYPESENSE_API_KEY=xyz

mkdir $(pwd)/typesense-data

docker run -p 8108:8108 \
            -v$(pwd)/typesense-data:/data typesense/typesense:0.26.0.rc58 \
            --data-dir /data \
            --api-key=$TYPESENSE_API_KEY \
            --enable-cors
➜  ~ export TYPESENSE_API_KEY=xyz

### Create a collection #############################################

➜  ~ curl -s "http://localhost:8108/collections" \
       -X POST \
       -H "Content-Type: application/json" \
       -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
       -d '{
         "name": "companies",
         "fields": [
           {"name": "company_name", "type": "string" }
         ]
       }'  | jq
{
  "created_at": 1708640450,
  "default_sorting_field": "",
  "enable_nested_fields": false,
  "fields": [
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "company_name",
      "optional": false,
      "sort": false,
      "stem": false,
      "type": "string"
    }
  ],
  "name": "companies",
  "num_documents": 0,
  "symbols_to_index": [],
  "token_separators": []
}

### Now update the schema to add a `type: auto` and `sort: true` field: ####################

➜  ~ curl -s 'http://localhost:8108/collections/companies' \
                -X 'PATCH' \
        -H "Content-Type: application/json" \
        -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
                -d '
{
  "fields": [
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "v#.*",
      "optional": true,
      "sort": true,
      "stem": false,
      "type": "auto"
    }
  ]
}
' | jq

{
  "message": "Field `v#.*` cannot be a sortable field."
}

### An error is returned above, but notice how the schema looks like now: ###################

➜  ~ curl -s -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" "http://localhost:8108/collections/companies" | jq
{
  "created_at": 1708640450,
  "default_sorting_field": "",
  "enable_nested_fields": false,
  "fields": [
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "company_name",
      "optional": false,
      "sort": false,
      "stem": false,
      "type": "string"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "v#.*",
      "optional": true,
      "sort": true,
      "stem": false,
      "type": "auto"
    }
  ],
  "name": "companies",
  "num_documents": 0,
  "symbols_to_index": [],
  "token_separators": []
}

### The invalid field still got added to the schema ########################################

Expected Behavior

After validation fails, the field should not be added to the schema.

Actual Behavior

After validation fails, the field is added to the schema, leaving the collection in an undefined state.

Metadata

Typesense Version: 0.26.0.rc58 and 0.25.2

OS: Docker / Ubuntu