首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在进行类型插入时接收RequestMalformed错误

在进行类型插入时接收RequestMalformed错误
EN

Stack Overflow用户
提问于 2022-10-12 00:36:45
回答 1查看 35关注 0票数 1

我在打字本中有以下界面:

代码语言:javascript
复制
export interface TypesenseAtlistedProEvent {
  // IDs
  id: string;
  proId: string;
  eventId: string;
  startTime: Number;
  stopTime: Number;
  eventRate: Number;
  remainingSlots: Number;
  displayName: string;
  photoURL: string;
  indexOptions: string;
  location: Number[];
}

以及Typesense中的下列模式:

代码语言:javascript
复制
{
  "created_at": 1665530883,
  "default_sorting_field": "location",
  "fields": [
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "proId",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "eventId",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "startTime",
      "optional": false,
      "sort": true,
      "type": "int64"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "stopTime",
      "optional": false,
      "sort": true,
      "type": "int64"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "eventRate",
      "optional": false,
      "sort": true,
      "type": "float"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "remainingSlots",
      "optional": false,
      "sort": true,
      "type": "int32"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "displayName",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "photoURL",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "indexOptions",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "location",
      "optional": false,
      "sort": true,
      "type": "geopoint"
    }
  ],
  "name": "atlistedProEventIndex",
  "num_documents": 0,
  "symbols_to_index": [],
  "token_separators": []
}

我希望在以下内容中重申如下:

代码语言:javascript
复制
const indexedDoc: TypesenseAtlistedProEvent = {
      id: proId + eventId,
      proId: proId,
      eventId: eventId,
      startTime: publicEvent.startTime.seconds,
      stopTime: publicEvent.stopTime.seconds,
      eventRate: publicEvent.eventRate,
      remainingSlots: publicEvent.remainingSlots,
      displayName: tpi.displayName,
      photoURL: tpi.photoURL,
      indexOptions: tpi.indexOptions,
      location: [tpi.lat, tpi.lng],
    };

return await typesenseClient
        .collections("atlistedProEventIndex")
          .documents()
          .upsert(indexedDoc)
          .then(() => {
            return {success: true, exit: 0};
          })

我在查询中得到以下信息:

RequestMalformed:请求失败,HTTP 400 \ Server说: json.exception.type_error.302类型必须是编号

我把它的位置作为Number[]传递给它,并试图让它更新类型中的geopoint。这是行不通的,因此,如果:

  1. I能够找到要通过的日志。我特别想要Typesense云给出的日志,我觉得我找不到这些日志。

  1. I想把geopoint作为打字本的正确类型传递。现在,正如您在上面看到的,位置是Number[]类型的,从我看到的示例来看,这个位置是正确的。也可能是另一个字段关闭了,而我只是错过了它。无论哪种方式,我都可以使用来自Typesense Cloud的某种服务器端日志记录。
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-12 20:08:33

错误消息有点混乱,但问题的核心是default_sorting_field只能是一个数字字段,但它目前被设置为一个geopoint字段(location),这就是该错误试图传达的内容。

因此,如果您在没有default_sorting_field的情况下创建了一个新集合,那么错误就不会出现。

如果要按地理位置进行排序,则需要使用sort_by参数:https://typesense.org/docs/0.23.1/api/geosearch.html#searching-within-a-radius

代码语言:javascript
复制
let searchParameters = {
  'q'         : '*',
  'query_by'  : 'title',
  'filter_by' : 'location:(48.90615915923891, 2.3435897727061175, 5.1 km)',
  'sort_by'   : 'location(48.853, 2.344):asc'
}

client.collections('companies').documents().search(searchParameters)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74035312

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档