gpt4 book ai didi

elasticsearch - elasticsearch排序未预期的null返回

转载 作者:行者123 更新时间:2023-12-02 23:00:23 25 4
gpt4 key购买 nike

我遵循doc https://www.elastic.co/guide/en/elasticsearch/guide/current/multi-fields.html名称字段添加排序列。不幸的是,它不起作用

这些步骤是:

  • 添加索引映射

  • PUT /staff
    {
    "mappings": {
    "staff": {
    "properties": {
    "id": {
    "type": "string",
    "index": "not_analyzed"
    },
    "name": {
    "type": "string",
    "fields": {
    "raw": {
    "type": "string",
    "index": "not_analyzed"
    }
    }
    }
    }
    }
    }
    }

  • 添加文档

  • POST /staff/list {
    "id": 5,
    "name": "abc"
    }

  • 搜索名称。原始

  • POST /staff_change/_search
    {
    "sort": "name.raw"
    }


    但是,响应中的排序字段返回 null
    "_source": {
    "id": 5,
    "name": "abc"
    },
    "sort": [
    null
    ]
    }

    我不知道为什么它不起作用,我无法搜索与此相关的相关问题文档。有人遇到这个问题吗

    提前谢谢了

    最佳答案

    您的映射不正确。您在索引staff内创建一个映射staff,然后在索引list内的映射staff下索引文档,该文档可以工作,但具有动态映射,而不是您添加的映射。最后,您将在索引staff中搜索所有文档。试试这个:

    PUT /staff
    {
    "mappings": {
    "list": {
    "properties": {
    "id": {
    "type": "string",
    "index": "not_analyzed"
    },
    "name": {
    "type": "string",
    "fields": {
    "raw": {
    "type": "string",
    "index": "not_analyzed"
    }
    }
    }
    }
    }
    }
    }

    然后索引:
    POST /staff/list {
    "id": 5,
    "name": "abc aa"
    }

    并查询:
    POST /staff/list/_search
    {
    "sort": "name.raw"
    }

    结果是:
    "hits": [
    {
    "sort": [
    "abc aa"
    ]
    }
    ...

    关于elasticsearch - elasticsearch排序未预期的null返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35835224/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com