ElasticSearch--使用字符串排序

DELETE /accounts
PUT /accounts
{
  "mappings": {
    "person": {
      "properties": {
        "name":{
          "type": "text"
        },
        "age":{
          "type": "integer"
        },
        "joinDate":{
          "type": "date"
        },
        "desc":{
          "type": "text",
          "fields": {
            "raw":{
              "type": "text",
              "index": "not_analyzed", 
              "fielddata": true
            }
          }
        }
      }
    }
  }
}
GET /accounts/_mapping/person
PUT /accounts/person/1
{
  "name":"sam",
  "age":20,
  "joinDate":"2020-01-01",
  "desc":"sam is a good boy!"
}
PUT /accounts/person/2
{
  "name":"zeng",
  "age":21,
  "joinDate":"2020-02-02",
  "desc":"zeng is a good boy!"
}
PUT /accounts/person/3
{
  "name":"jim jack",
  "age":22,
  "joinDate":"2020-03-03",
  "desc":"jim is a good boy!"
}
GET /accounts/person/_search
{
  "query": {
    "match_all": {}
  },
  "sort": [
    {
      "desc.raw": {
        "order": "desc"
      }
    }
  ]
}

关键在如下所示的设置:建立一个不分词的索引,用来排序:

"desc":{
          "type": "text",
          "fields": {
            "raw":{
              "type": "text",
              "index": "not_analyzed", 
              "fielddata": true
            }
          }
        }

本人测试后发现"index": "not_analyzed"根本就没有生效,导致desc字段还是分词处理过,不知道是啥原因,所以请教一下有知道的小伙伴,不胜感激!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值