elasticsearh中查询时出现‘Fielddata is disabled on text fields by default. Set fielddata=true on [operatetime] in order to load fielddata in memory by uninverting the inverted index...’

当像往常一样查询es中的日志的时候发现查不出来数据。根据报错排查发现是排序字段的类型问题。查找官方文档发现:5.x之后,elasticsearch对排序、聚合所依据的字段用单独的数据结构(fielddata)缓存到内存里,但是在text类型字段是默认禁用的,如果需要则要单独开启,这样做的方法是为了节省内存空间。

根据文档提示发现我进行查询的排序字段operatetime确实是text类型的,所以解决方法有两个:

1.修改fielddata为true

PUT testindex/_mapping/texttype

{

 "properties": {

     "operatetime": {

   "type": "text",

   "fielddata": "true"

         }

   }

}

2.直接在创建索引的时候将要排序的字段创建为keyword类型的

原文地址:https://www.cnblogs.com/olzoooo/p/12454824.html