ElasticSearch Fielddata is disabled

初次学习 Elasticsearch 在参照文档实例 挖掘出员工中最受欢迎的兴趣爱好 这一章节时,执行命令

curl -X GET "localhost:9200/megacorp/employee/_search?pretty" -H ‘Content-Type: application/json‘ -d‘{
  "aggs": {
    "all_interests": {
      "terms": { "field": "interests" }
    }
  }
}‘

出现如下的错误信息

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [interests] 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": "megacorp",
        "node": "8UDhP_KCSz6CNmKNyyFriQ",
        "reason": {
          "type": "illegal_argument_exception",
          "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [interests] 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."
        }
      }
    ]
  },
  "status": 400
}

具体原因是聚合查询需要大量的内存,去和前,需要将相应的字段开启聚合。

curl -X PUT "localhost:9200/megacorp/_mapping/employee" -H ‘Content-Type: application/json‘ -d‘{
  "properties": {
    "interests": {
      "type": "text",
      "fielddata": true
    }
  }
}‘

ElasticSearch Fielddata is disabled

上一篇:JDK环境配置


下一篇:Nginx 做图片服务器 在项目中的使用实例