Strange issue when seeding my database, we can see...
# community-help
j
Strange issue when seeding my database, we can see errors for every single document, with a nested array of objects, I'm allowing typesense to cast these values by provided
object[]
to the field type, all the fields are floats, but it says needs to be array of int64? please advise schema
Copy code
{
  name: 'aggregatedLaneDocuments',
  fields: [
    { name: 'documentType', type: 'string' },
    { name: 'lane.origin.name', type: 'string', facet: true },
    { name: 'lane.origin.metro', type: 'string', facet: true },
    { name: 'lane.origin.type', type: 'string', facet: true },
    { name: 'lane.origin.address.street', type: 'string', facet: true },
    { name: 'lane.origin.address.city', type: 'string', facet: true },
    { name: 'lane.origin.address.state', type: 'string', facet: true },
    { name: 'lane.origin.address.zip', type: 'string', facet: true },
    { name: 'lane.origin.geolocation', type: 'geopoint', optional: true },
    { name: 'lane.destination.name', type: 'string', facet: true },
    { name: 'lane.destination.geolocation', type: 'geopoint', optional: true },
    { name: 'cluster', type: 'string', facet: true },
    { name: 'numberOfRates', type: 'int32' },
    { name: 'averageRate', type: 'float' },
    { name: 'simpleAverageRate', type: 'float', optional: true },
    { name: 'medianRate', type: 'float', optional: true },
    { name: 'rateRange.min', type: 'float', optional: true },
    { name: 'rateRange.max', type: 'float', optional: true },
    { name: 'standardDeviation', type: 'float', optional: true },
    { name: 'currency', type: 'string' },
    { name: 'confidenceScore', type: 'float', optional: true },
    { name: 'mostRecentRateAge', type: 'int32', optional: true },
    { name: 'weightedRpm', type: 'float', optional: true },
    { name: 'referencePoints', type: 'object[]', optional: true },
    { name: 'trend', type: 'string', optional: true },
    { name: 'timeline.entries', type: 'object[]', optional: true },
  ],
  enable_nested_fields: true,
  default_sorting_field: 'numberOfRates',
}
document
Copy code
{
  "averageRate": 228.5,
  "cluster": "(DET) Cluster 1",
  "confidenceScore": 76,
  "currency": "USD",
  "documentType": "aggregatedLane",
  "id": "03b5d758a57f4b358baa01cc8e75e307",
  "lane": {
    "destination": {
      "geolocation": [
        42.3369816,
        -83.27326269999999
      ],
      "name": "Dearborn Heights, MI"
    },
    "origin": {
      "address": {
        "city": "Detroit",
        "state": "MI",
        "street": "12594 Westwood Street",
        "zip": "48223"
      },
      "cluster": "(DET) Cluster 1",
      "geolocation": [
        42.3809394,
        -83.2215499
      ],
      "metro": "DET",
      "name": "Detroit CPKC",
      "type": "rail"
    }
  },
  "lastUpdated": {
    "__time__": "2025-01-12T08:02:38.821Z"
  },
  "medianRate": 228.5,
  "metro": "DET",
  "mostRecentRateAge": 25,
  "numberOfRates": 6,
  "rateRange": {
    "max": 240,
    "min": 217
  },
  "referencePoints": [
    {
      "destination": "Dearborn Heights, MI",
      "distance": 4,
      "numberOfRates": 6,
      "origin": "Detroit CPKC",
      "rate": 228.5, <-------------------------------
      "rpm": 56.71,
      "weight": 0.892
    },
    {
      "destination": "Dearborn Heights, MI",
      "distance": 8,
      "numberOfRates": 6,
      "origin": "Detroit Rail Terminal",
      "rate": 228.5, <-------------------------------
      "rpm": 28.33,
      "weight": 0.725
    },
    {
      "destination": "Dearborn Heights, MI",
      "distance": 8,
      "numberOfRates": 4,
      "origin": "Detroit NS Livernois",
      "rate": 228.50000000000003, <-------------------------------
      "rpm": 28.16,
      "weight": 0.622
    }
  ],
  "simpleAverageRate": 228.5,
  "standardDeviation": 11.5,
  "timeline": {
    "entries": [
      {
        "date": "2024-12-12",
        "id": "2024-12-12_215",
        "rate": 215
      },
      {
        "date": "2024-12-12",
        "id": "2024-12-12_245",
        "rate": 245
      },
      {
        "date": "2024-12-13",
        "id": "2024-12-13_231",
        "rate": 231
      },
      {
        "date": "2024-12-18",
        "id": "2024-12-18_240",
        "rate": 240
      },
      {
        "date": "2024-12-18",
        "id": "2024-12-18_217",
        "rate": 217
      }
    ]
  },
  "trend": "decreasing",
  "weightedRpm": 39.59
}
Error adding document 035e68bff2c2d75036d04e1a9d8df3a2: Request failed with HTTP code 400 | Server said: Field referencePoints.rate must be an array of int64.
f
You must have previously indexed a document where
refetencePoints.rate
was an integer. The first time you index a document with an object field, Typesense will auto-infer its children's types
r
better to explicitly declare the object schema in this scenario
1
f
Whatever suits your needs! I do prefer strict statically typed schemas myself, but that's up to you
1
r
Alternatively, make sure that you cast values consistently from wherever you are feeding your seeding data. If it is alternating between integer and float, that could indicate type juggling, and thus is not consistent.
1