码迷,mamicode.com
首页 > 其他好文 > 详细

Elasticsearch聚合问题

时间:2019-08-18 23:59:31      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:index   use   sign   get   keyword   employee   信息   last   inter   

 在测试Elasticsearch聚合的时候报了一个错误。具体如下:

GET /megacorp/employee/_search
{
  "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": "wlvuJ0f_SsCxys6ZW5j7eA",
        "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
}

解决方案:

1、ElasticSearch5.x的解决方法是这样开启fielddata的:

PUT /megacorp/_mapping/employee
{
  "properties": {
    "interests": { 
      "type": "text",
      "fielddata": true
    }
  }
}

2、版本为ElasticSearch6.x或者7.x时开启fielddata的:

PUT /megacorp/_mapping
{
  "properties": {
    "interests": { 
      "type": "text",
      "fielddata": true
    }
  }
}

 

Elasticsearch聚合问题

标签:index   use   sign   get   keyword   employee   信息   last   inter   

原文地址:https://www.cnblogs.com/liugp/p/11374524.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!