我在es中存了约50w条nginx日志,想查询出响应时间最长的几个请求,按照下面的查询语句,返回400:
GET /test1/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"milliseconds": {
"order": "desc"
}
}
]
}
返回结果:
告诉我"Fielddata is disabled on text fields by default. Set fielddata=true on [milliseconds] in order to load fielddata in memory by uninverting the inverted index."意思是需要设置milliseconds字段的fielddata为true。
解决办法:
首先查询索引信息:
GET /test1
得到结果:
milliseconds就在mappings>doc>properties下面,用下面的请求将fielddata设为true:
PUT /test1/_mapping/doc/?pretty
{
"properties":{
"milliseconds":{
"fielddata":true
}
}
}
得到结果:
再次用原来的语句查询,则成功得到结果: