zoukankan      html  css  js  c++  java
  • Elasticsearch聚合问题

     在测试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
        }
      }
    }
  • 相关阅读:
    Spring Cloud 模块简介2
    Eureka简介
    Spring Cloud 模块简介
    成神之路-基础篇 转
    Java面试题无答案
    java程序猿常用Linux命令
    Java工程师成神之路 转
    大型网站技术架构 大纲
    Mockito 相关资料
    webApp路由控制-vue-router2.0
  • 原文地址:https://www.cnblogs.com/liugp/p/11374524.html
Copyright © 2011-2022 走看看