admin管理员组

文章数量:1531724

es aggs聚合的fielddata=true

报错信息(默认es不支持对text字段聚合,需要请打开某些开关)

Please use a keyword field instead。set fielddata=true on [tag]
{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [tag] in order to load field data by uninverting the inverted index. Note that this can use significant memory."
      }
    ],
    "type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "grouped" : true,
    "failed_shards" : [
      {
        "shard" : 0,
        "index" : "crazy",
        "node" : "kyaA90j2QjSFjUIlCL7cBg",
        "reason" : {
          "type" : "illegal_argument_exception",
          "reason" : "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [tag] in order to load field data by uninverting the inverted index. Note that this can use significant memory."
        }
      }
    ],
    "caused_by" : {
      "type" : "illegal_argument_exception",
      "reason" : "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [tag] in order to load field data by uninverting the inverted index. Note that this can use significant memory.",
      "caused_by" : {
        "type" : "illegal_argument_exception",
        "reason" : "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [tag] in order to load field data by uninverting the inverted index. Note that this can use significant memory."
      }
    }
  },
  "status" : 400
}
打开fielddata=true
POST /crazy/_doc
{
  "properties":{
    "tag":{
      "type":"text",
      "fielddata":true
    }
  }
}
// 返回
{
  "_index" : "crazy",
  "_type" : "_doc",
  "_id" : "OOqnLXMB85eJEC73N3Gb",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 3,
    "successful" : 3,
    "failed" : 0
  },
  "_seq_no" : 10,
  "_primary_term" : 1
}

注意:这样会取消es的倒排索引功能,并且很吃内存

声明:
博客中标注原创的文章,版权归本博客作者所有,若转载或者引用本文内容请注明来源及原作者,否则依法保留追究权
打赏功能被文章底部的···默认隐藏了,如果帮到你了点个赞呗【嘘~~~悄悄话:挣钱买房吧骚年】

本文标签: 操作eskibanatrueFielddata