使用先前存在的索引的新映射创建新索引

时间:2019-01-12 22:07:49

标签: elasticsearch autocomplete mapping reindex search-suggestion

{
  "someindex": {
    "aliases": {
      "somealias": {}
    },
    "mappings": {},
    "settings": {
      "index": {
        "number_of_shards": "5",
        "provided_name": "someindex",
        "creation_date": "1547325991414",
        "analysis": {
          "filter": {
            "autocomplete_filter": {
              "type": "edge_ngram",
              "min_gram": "1",
              "max_gram": "20"
            }
          },
          "normalizer": {
            "lowerCaseNormalizer": {
              "filter": [
                "lowercase"
              ],
              "type": "custom"
            }
          },
          "analyzer": {
            "standard": {
              "filter": [
                "lowercase",
                "autocomplete_filter"
              ],
              "type": "custom",
              "tokenizer": "standard"
            }
          }
        },
        "number_of_replicas": "1",
        "uuid": "9vrt0U90RWG-4MRQEIbj6w",
        "version": {
          "created": "6050499"
        }
      }
    }
  }
}

上面是我新创建的结构的结构。在当前设置中,我的当前索引上有一个名为bookName的属性,针对该属性的当前映射如下:

{
  "bookName": {
    "type": "text",
    "fields": {
      "keyword": {
        "type": "keyword",
        "ignore_above": 256,
        "normalizer": "lowerCaseNormalizer"
      }
    }
  }
}

现在,当我尝试重新索引名为“ someindex ”的新索引并想为bookName字段插入新映射时,它给了我错误。”

{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "Root mapping definition has unsupported parameters:  [mappings : {details={properties={suggest={type=completion}, bookName={type=text, analyzer=standard}}}}]"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "Root mapping definition has unsupported parameters:  [mappings : {details={properties={suggest={type=completion}, bookName={type=text, analyzer=standard}}}}]"
  },
  "status": 400
}

我已经尝试了所有方法,并且能够从头开始对随机数据进行测试。但是,我必须在我的项目中介绍此功能,并且我已经准备好一个具有不同映射关系的弹性索引。迁移让我很困扰。有人可以指导我如何实现此目标的适当程序。

注意:我已经尝试了所有方法,搜索了Elastic文档和所有相关链接。我可以在新数据集上进行操作,但是迁移对我来说是个真正的问题,因为我是该领域的新手。

1 个答案:

答案 0 :(得分:0)

要更新索引的映射,您必须使用put mapping api。因此,要更新映射,请使用以下请求:

PUT someindex/_mappings/_doc
{
  "properties": {
    "bookName": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256,
          "normalizer": "lowerCaseNormalizer"
        }
      }
    }
  }
}

请注意,我假设映射名称为_doc