映射器与现有映射冲突



我有一个关于索引类型中属性的更新分析器的问题。我已经在这里阅读了这种错误的问题。但事实并非如此,因为我只有一种索引类型(实验),而且它是唯一的,不可能冲突。这是来自 elasticsearch 2.3。

映射

(get "/public-search/_mapping/developer")
{:public-search {:mappings {:developer {:properties {:db/id {:type "long"}, :developer/description {:type "string"}, :developer/established-date {:type "date", :format "strict_date_optional_time||epoch_millis"}, :developer/logo-url {:type "string"}, :developer/name {:type "string"}, :developer/total-project {:type "long"}}}}}}
// I do have autocomplete analyzer in settings
(put "/public-search/_mapping/developer"
       {:properties {:developer/name {:type "string"
                                      :analyzer "autocomplete"}}})
{:error {:root_cause [{:type "illegal_argument_exception", :reason "Mapper for [developer/name] conflicts with existing mapping in other types:n[mapper [developer/name] has different [analyzer]]"}], :type "illegal_argument_exception", :reason "Mapper for [developer/name] conflicts with existing mapping in other types:n[mapper [developer/name] has different [analyzer]]"}, :status 400}

如果我在将数据放入之前创建映射,则可以正常工作。但我仍然担心在运行时更新映射。在这种情况下可能出现什么问题?

如果我在将数据放入之前创建映射就可以了。

这说明了一切,不是吗?


如果您先插入数据而没有映射,ES 将猜测您的数据类型,然后根据它创建映射。查看 ES 为数据生成的映射。

我建议,它不完全是你想要创建的映射。

简单示例:插入"字符串"2016-01-01T00:00:00.000Z。ES 将创建一个日期时间字段,即使您需要一个字符串字段。为了获取字符串字段,您必须在插入数据之前创建映射。

此外,ES无法猜测分析仪等。而且(如果我没记错的话)在插入数据后无法覆盖它们。

作为一种解决方法,我使用预期的映射重新创建了索引...

# Create a temp index
kubectl exec elasticsearch-master-0  -- curl -X PUT 'http://elasticsearch-master:9200/<temp index name>/' -H 'Content-Type: application/json' -d'
{
   "settings": {
      "analysis": {
         "analyzer": {
            "path_analyzer": {
               "tokenizer": "path_tokenizer"
            }
         },
         "tokenizer": {
            "path_tokenizer": {
               "type": "path_hierarchy",
               "delimiter": "."
            }
         }
      }
   }
}
'
# Create a mapping in the temp index
kubectl exec elasticsearch-master-0  -- curl -X PUT 'http://elasticsearch-master.utility:9200/<temp index name>/_mappings' -H 'Content-Type: application/json' -d'
{
      "properties": {
        "activity_time": {
          "type": "date",
          "format": "epoch_second"
        }
      }
}
'
# Reindex from the origin index to the temp index
kubectl exec elasticsearch-master-0  -- curl  -X POST  'http://elasticsearch-master:9200/_reindex?pretty' -H 'Content-Type: application/json' -d'
{
"source": {
"index": "<original index name>"
},
"dest": {
"index": "<temp index name>"
}
}
' 
# Delete the origin index
kubectl exec elasticsearch-master-0 -- curl --location --request DELETE 'http://elasticsearch-master:9200/<original index name>/'
# Recreate the origin index with setting if it has
kubectl exec elasticsearch-master-0  -- curl --location --request PUT 'http://elasticsearch-master:9200/<original index name>/' -H 'Content-Type: application/json' -d'
{
   "settings": {
      "analysis": {
         "analyzer": {
            "path_analyzer": {
               "tokenizer": "path_tokenizer"
            }
         },
         "tokenizer": {
            "path_tokenizer": {
               "type": "path_hierarchy",
               "delimiter": "."
            }
         }
      }
   }
}
'
# Create a mapping in the index
kubectl exec elasticsearch-master-0 -n utility -- curl -X PUT 'http://elasticsearch-master:9200/<original index name>/_mappings' -H 'Content-Type: application/json' -d'
{
      "properties": {
        "activity_time": {
          "type": "date",
          "format": "epoch_second"
        }
}
'
# Reindex from the temp index to the new origin index
kubectl exec elasticsearch-master-0 -- curl  -X POST  'http://elasticsearch-master:9200/_reindex?pretty' -H 'Content-Type: application/json' -d'
{
"source": {
"index": "<temp index name>"
},
"dest": {
"index": "<original index name>"
}
}
' 

最新更新