The sorting by `ID` does not appear to be working ...
# community-help
a
The sorting by
ID
does not appear to be working as expected. Below is the query I am currently using:
Copy code
{
  "q": "*",
  "page": 1,
  "per_page": 20,
  "filter_by": "id:=[213186,208844,200988,210871,210879,210887,210619,184357,203731]",
  "exclude_fields": "embedding",
  "sort_by": "_eval([(id:`213186`):10000,(id:`208844`):9999,(id:`200988`):9998]):desc"
}
h
Can you try again with
Copy code
"sort_by": "_eval([(id: 213186):10000,(id: 208844):9999,(id: 200988):9998]):desc"
a
It seems to be not working.
h
@Athul Can you share a minimal example for this issue in this format? https://gist.github.com/jasonbosco/7c3432713216c378472f13e72246f46b
a
Copy code
#!/bin/bash
set -x

export TYPESENSE_API_KEY=xyz
export TYPESENSE_HOST=<http://localhost:8108>

# Cleanup old containers/data
docker stop typesense-repro 2>/dev/null
docker rm typesense-repro 2>/dev/null
rm -rf "$(pwd)"/typesense-data-dir-repro
mkdir "$(pwd)"/typesense-data-dir-repro

# Start Typesense container
docker run -d -p 8108:8108 --name typesense-repro \
            -v"$(pwd)"/typesense-data-dir-repro:/data \
            typesense/typesense:29.0.rc31 \
            --data-dir /data \
            --api-key=$TYPESENSE_API_KEY \
            --enable-cors

# Wait until Typesense is ready
until curl -s -o /dev/null -w "%{http_code}" "$TYPESENSE_HOST/health" -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" | grep -q "200"; do
  sleep 2
done

# Debug info
curl -s "$TYPESENSE_HOST/debug" \
       -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" | jq

# Create collection
curl -s "$TYPESENSE_HOST/collections" \
       -X POST \
       -H "Content-Type: application/json" \
       -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
       -d '
          {
             "name": "documents",
             "fields": [
               {"name": "id", "type": "int64"},
               {"name": "title", "type": "string" },
               {"name": "embedding", "type": "float[]", "optional": true }
             ]
           }' | jq

# Import your test docs
curl -s "$TYPESENSE_HOST/collections/documents/documents/import?action=create" \
        -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
        -H "Content-Type: text/plain" \
        -X POST \
        -d ' 
{"id": "213186", "title": "Doc 213186"}
{"id": "208844", "title": "Doc 208844"}
{"id": "200988", "title": "Doc 200988"}
{"id": "210871", "title": "Doc 210871"}
{"id": "210879", "title": "Doc 210879"}
{"id": "210887", "title": "Doc 210887"}
{"id": "210619", "title": "Doc 210619"}
{"id": "184357", "title": "Doc 184357"}
{"id": "203731", "title": "Doc 203731"}
' | jq

# Run your query with _eval sorting
curl -s "$TYPESENSE_HOST/collections/documents/documents/search" \
        -X GET \
        -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
        --get \
        --data-urlencode 'q=*' \
        --data-urlencode 'query_by=title' \
        --data-urlencode 'page=1' \
        --data-urlencode 'per_page=20' \
        --data-urlencode 'filter_by=id:=[213186,208844,200988,210871,210879,210887,210619,184357,203731]' \
        --data-urlencode 'exclude_fields=embedding' \
        --data-urlencode 'sort_by=_eval([(id:213186):10000,(id:208844):9999,(id:200988):9998, (id:210619):9997]):desc' \
        | jq

# Stop container
docker stop typesense-repro
docker rm typesense-repro
h
The response should be in this order, right?
Copy code
{"id": "213186", "title": "Doc 213186"}
{"id": "208844", "title": "Doc 208844"}
{"id": "200988", "title": "Doc 200988"}
{"id": "203731", "title": "Doc 203731"}
{"id": "184357", "title": "Doc 184357"}
{"id": "210619", "title": "Doc 210619"}
{"id": "210887", "title": "Doc 210887"}
{"id": "210879", "title": "Doc 210879"}
{"id": "210871", "title": "Doc 210871"}
a
yes
👍🏼 1
Hi @Harpreet Sangar, have you been able to reproduce the bug?
h
I haven't been able to pick this issue yet. I'll let you know once I do.
a
Okay
@Harpreet Sangar
h
a
Hey @Athul , fix available in v30.0.rc15