gpt4 book ai didi

elasticsearch - Elasticsearch 排序问题

转载 作者:行者123 更新时间:2023-12-03 01:03:03 24 4
gpt4 key购买 nike

对于我的 flex 搜索,我具有以下参数

  • BookName:\"type\":\"string\
  • IsFeaturedBook:\"type\":\"string\"(但保存是非题)
  • IsSoldOutBook:\"type\":\"boolean\",\"index\":\"no\",\"include_in_all\": false(保存是非题)

  • 以下查询:
    "sort" :[{ "BookName" : {"order" : "asc"}}]

    以升序对包名称进行排序

    以下查询:
    "sort" :[{ "IsFeaturedBook" : {"order" : "asc"}}]

    要么
    "sort" :[{ "IsFeaturedBook" : "asc"}]

    对IsFeaturedBook进行排序,因为它的类型是字符串

    但是, bool(boolean) 类型IsSoldOutBook无法与以下任何查询进行排序,我怀疑其原因是 bool(boolean) 类型,
    "sort" :[{ "IsSoldOutBook" : {"order" : "asc"}}]

    要么
    "sort" :[{ "IsSoldOutBook" : "asc"}].

    请让我知道我该如何实现?其次 { "IsFeaturedBook" : {"order" : "asc"}{ "IsFeaturedBook" : "asc"}之间有什么区别

    最佳答案

    您的问题是"index": "no"。 Elasticsearch尝试按该字段排序,但是,如果未对该字段进行索引,则按null值排序。

    看到这个复制品:

    DELETE /test

    PUT /test
    {
    "mappings": {
    "sample": {
    "properties": {
    "field": {
    "type": "boolean",
    "index": "no"
    }
    }
    }
    }
    }

    PUT /test/sample/1
    { "field": true }
    PUT /test/sample/2
    { "field": false }
    PUT /test/sample/3
    { "field": true }

    让我们运行以下查询:
    GET /test/_search
    {
    "query": {
    "match_all": {}
    },
    "sort": [
    {
    "field": {
    "order": "asc"
    }
    }
    ]
    }

    因此,现在当您尝试按 field进行排序时,它将选择 null值,并且由于它们都是相等的-不会有任何影响。这是上面查询的结果。
    {
    "took": 2,
    "timed_out": false,
    "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
    },
    "hits": {
    "total": 3,
    "max_score": null,
    "hits": [
    {
    "_index": "test",
    "_type": "sample",
    "_id": "1",
    "_score": null,
    "_source": {
    "field": true
    },
    "sort": [
    null
    ]
    },
    {
    "_index": "test",
    "_type": "sample",
    "_id": "2",
    "_score": null,
    "_source": {
    "field": false
    },
    "sort": [
    null
    ]
    },
    {
    "_index": "test",
    "_type": "sample",
    "_id": "3",
    "_score": null,
    "_source": {
    "field": true
    },
    "sort": [
    null
    ]
    }
    ]
    }
    }

    为了解决此问题,请从属性中删除 "index": "no"。我自己尝试过,效果很好。然后,您会看到 "sort": "T""sort": "F",它们会很好地工作。

    关于elasticsearch - Elasticsearch 排序问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34676444/

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