ES6 Fielddata is disabled on text fields by default

使用ES做聚合运算的时候,有时候会遇到这个错误

Fielddata is disabled on text fields by default. Set fielddata=true on [host] 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.

这时候有两个解决办法:一个是设置字段开启fielddata  一个是查询的时候使用字段名称加keyword

具体方法可以参考官方文档:

   https://www.elastic.co/guide/en/elasticsearch/reference/current/text.html#enable-fielddata-text-fields

解决方法请尝试开启这个字段:

PUT filebeat-2020.12.19.19

{
  "mappings": {
    "type": {
      "properties": {
        "host": {
          "type": "text",
          "fielddata": true
        }
      }
    }
  }
}
PUT web-nginx-5xxlog-2020.12/_mapping/log
{
    "properties":{
        "host":{
            "type":"text",
            "fielddata":true
        },
        "url":{
            "type":"text",
            "fielddata":true
        }
        
    }
}

参考文档:

     https://www.cnblogs.com/xingxia/p/elasticsearch_problems.html

原文地址:https://www.cnblogs.com/topicjie/p/14161098.html