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字段还是分词处理过,不知道是啥原因,所以请教一下有知道的小伙伴,不胜感激!!!