我一直在使用ES 5.4.0版本,并创建了索引和文档(学生数据)。当我根据年龄进行搜索时,_search终点返回值,并且输出符合预期。对name desc选项做了相同的操作。我低于异常
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [name] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "students",
"node": "MESiRCvSSgqMNWEVwMevMg",
"reason": {
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [name] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
可能是原因。根据日志,我必须添加fileddata = true。出于任何原因。
http://localhost:9200/students/data/_search?q=montana&sort=age:desc-运行正常。
http://localhost:9200/students/data/_search?q=montana&sort=name:desc-不起作用
http://localhost:9200/students/data/_search?q=montana&sort=name:desc&fielddata=true-添加了字段数据-不起作用
// http://localhost:9200/students?
{
"students": {
"aliases": {
},
"mappings": {
"data": {
"properties": {
"age": {
"type": "long"
},
"city": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"company": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"email": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"gender": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"phone": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"state": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"street": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
},
"settings": {
"index": {
"creation_date": "1530174012103",
"number_of_shards": "5",
"number_of_replicas": "1",
"uuid": "PrtajDL0SwS-tTX7Gm_YQw",
"version": {
"created": "5040099"
},
"provided_name": "students"
}
}
}
}
答案 0 :(得分:1)
您不能在text
字段上排序(可以,但是结果没有意义),但是,您可以在keyword
字段上排序,因此以下查询将起作用:>
http://localhost:9200/students/data/_search?q=montana&sort=name.keyword:desc
^
|
add this