4

我有一个字段的现有映射,我想将其更改为多字段。

现有的映射是

{
   "my_index": {
      "mappings": {
         "my_type": {
            "properties": {
               "author": {
                  "type": "string"
               },
               "isbn": {
                  "type": "string",
                  "analyzer": "standard",
                  "fields": {
                     "ngram": {
                        "type": "string",
                        "search_analyzer": "keyword"
                     }
                  }
               },
               "title": {
                  "type": "string",
                  "analyzer": "english",
                  "fields": {
                     "std": {
                        "type": "string",
                        "analyzer": "standard"
                     }
                  }
               }
            }
         }
      }
   }
}

根据文档,我应该能够通过执行以下操作将“作者”更改为多字段

PUT /my_index
{
  "mappings": {
        "my_type": {
            "properties": {
                "author": 
                { 
                    "type": "multi-field",
                    "fields": {
                        "ngram": {
                          "type": "string",
                          "indexanalyzer": "ngram_analyzer",
                          "search_analyzer": "keyword"
                        },
                         "name" : {
                         "type": "string"
                        }
                    }
                }              
            }
        }
    }
}

但相反,我收到以下错误:

{
"error": "IndexAlreadyExistsException[[my_index] already exists]",
"status": 400
}

我错过了一些非常明显的东西吗?

4

3 回答 3

1

您将无法更改现有索引中的字段类型。如果您无法重新创建索引,您可以使用复制到字段来实现类似的功能。

   PUT /my_index
        {
          "mappings": {
           "my_type": {
        "properties": {
                   "author": 
                   { 
                      "type": "string",
                      "copy_to": ["author-name","author-ngram"]
                   }

                    "author-ngram": {
                      "type": "string",
                      "indexanalyzer": "ngram_analyzer",
                      "search_analyzer": "keyword"
                    },
                     "author-name" : {
                     "type": "string"
                    }

            }              
          }
       }
     }
  }
于 2014-12-17T17:41:19.887 回答
1

而不是 PUT 到 /my_index 做:

POST /my_index/_mapping
于 2014-12-17T16:54:20.443 回答
1

虽然我没有在您的特定示例中尝试过,但确实可以通过首先关闭索引然后应用映射来更新字段映射。

例子:

POST /my_index/_close
POST /my_index/_mapping
{
     "my_field:{"new_mapping"}
}
POST /my_index/_open

我已经通过向映射字段添加“copy_to”映射属性对其进行了测试。

基于https://gist.github.com/nicolashery/6317643

于 2015-10-28T19:54:12.560 回答