ElasticSearch:Mapping 数据迁移

1、Mapping属性错误

“type”: “illegal_argument_exception”,
“reason”: “Can’t load fielddata on [brandName] because fielddata is unsupported on fields of type [keyword]. Use doc values instead.”

因属性中设置doc_values 为false导致keyword类型不支持

解决方式:调整Mapping字段
原有数据Mapping:

{
  "product" : {
    "mappings" : {
      "properties" : {
        "brandId" : {
          "type" : "long"
        },
        "brandImg" : {
          "type" : "keyword",
          "index" : false,
          "doc_values" : false
        },
        "brandName" : {
          "type" : "keyword",
          "index" : false,
          "doc_values" : false
        },
        "catalogId" : {
          "type" : "long"
        },
        "catalogName" : {
          "type" : "keyword",
          "index" : false,
          "doc_values" : false
        },
        "hasStock" : {
          "type" : "boolean"
        },
        "hotScore" : {
          "type" : "long"
        },
        "saleCount" : {
          "type" : "long"
        },
        "skuId" : {
          "type" : "long"
        },
        "skuImg" : {
          "type" : "keyword",
          "index" : false,
          "doc_values" : false
        },
        "skuPrice" : {
          "type" : "keyword"
        },
        "skuTitle" : {
          "type" : "text",
          "analyzer" : "ik_smart"
        },
        "spuId" : {
          "type" : "keyword"
        }
      }
    }
  }
}
A.创建新Mapping

去掉当前doc_values设置或者设置为true

PUT shop_product
{
    "mappings" : {
      "properties" : {
        "brandId" : {
          "type" : "long"
        },
        "brandImg" : {
          "type" : "keyword"
        },
        "brandName" : {
          "type" : "keyword"
        },
        "catalogId" : {
          "type" : "long"
        },
        "catalogName" : {
          "type" : "keyword"
        },
        "hasStock" : {
          "type" : "boolean"
        },
        "hotScore" : {
          "type" : "long"
        },
        "saleCount" : {
          "type" : "long"
        },
        "skuId" : {
          "type" : "long"
        },
        "skuImg" : {
          "type" : "keyword"
        },
        "skuPrice" : {
          "type" : "keyword"
        },
        "skuTitle" : {
          "type" : "text",
          "analyzer" : "ik_smart"
        },
        "spuId" : {
          "type" : "keyword"
        }
      }
    }
  }
B.迁移数据
POST _reindex
{
  "source": {
    "index": "product"
  },
  "dest": {
    "index": "shop_product"
  }
}
C.数据查询
GET shop_product/_search

你可能感兴趣的:(JAVA,分布式架构,elasticsearch,es,java)