【问题标题】:Uppercase letters should come first in elastic search大写字母在弹性搜索中应该排在第一位
【发布时间】:2021-01-08 06:53:39
【问题描述】:

我有一些数据,例如... 芒果, 苹果, 香蕉, 胡萝卜

我正在寻找弹性搜索排序查询,它应该给出结果,因为大写字母应该排在前面,如下所示

香蕉, 芒果, 苹果, 胡萝卜

任何人都可以帮助我如何为此要求准备查询。谢谢

【问题讨论】:

    标签: elasticsearch elasticsearch-painless


    【解决方案1】:

    使用keyword 字段并以asc 的顺序对数据进行排序,您将能够得到您想要的结果。

    添加一个包含索引数据、映射、搜索查询和搜索结果的工作示例

    索引映射:

    {
      "mappings": {
        "properties": {
          "name": {
            "type": "keyword"
          }
        }
      }
    }
    

    索引数据:

    {
      "name": "apple"
    }
    {
      "name": "Banana"
    }
    {
      "name": "Mango"
    }
    {
      "name": "carrot"
    }
    

    搜索查询:

    {
      "sort": [
        {
          "name": {
            "order": "asc"
          }
        }
      ]
    }
    

    搜索结果:

    "hits": [
          {
            "_index": "65624606",
            "_type": "_doc",
            "_id": "3",
            "_score": null,
            "_source": {
              "name": "Banana"
            },
            "sort": [
              "Banana"
            ]
          },
          {
            "_index": "65624606",
            "_type": "_doc",
            "_id": "1",
            "_score": null,
            "_source": {
              "name": "Mango"
            },
            "sort": [
              "Mango"
            ]
          },
          {
            "_index": "65624606",
            "_type": "_doc",
            "_id": "2",
            "_score": null,
            "_source": {
              "name": "apple"
            },
            "sort": [
              "apple"
            ]
          },
          {
            "_index": "65624606",
            "_type": "_doc",
            "_id": "4",
            "_score": null,
            "_source": {
              "name": "carrot"
            },
            "sort": [
              "carrot"
            ]
          }
        ]
    

    【讨论】:

    • 感谢 ASCII !解释如何实现相反的效果会很有趣,即先小写:-)
    • @Venu 你有没有机会浏览一下答案,期待得到你的反馈?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-01
    • 2011-10-17
    相关资源
    最近更新 更多