Elasticsearch:修改fielddata

GET twitter/_search
{
  "query": {
    "match": {
      "city": "北京"
    }
  },
  "aggs":{
    "count_city":{
      "terms": {
        "field": "city"
      }
    }
  }
}

执行以上操作报错,报错内容如下:

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [city] 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": "twitter",
        "node": "mFpXLptTTLKEMHwOAGFZjg",
        "reason": {
          "type": "illegal_argument_exception",
          "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [city] 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."
        }
      }
    ],
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [city] 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.",
      "caused_by": {
        "type": "illegal_argument_exception",
        "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [city] 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
}

修改fielddata

PUT /twitter/_mapping/
{
  "properties": {
    "city": { 
      "type": "text",
      "fielddata": true
    }
  }
}
posted @ 2020-05-09 10:52  fat_girl_spring  阅读(1397)  评论(0编辑  收藏  举报