gpt4 book ai didi

elasticsearch - 无法在ElasticSearch中将映射更改为non_analyzed

转载 作者:行者123 更新时间:2023-12-02 23:27:46 25 4
gpt4 key购买 nike

我有一个具有以下映射的文档类型:

GET my_index/my_doctype/_mapping
{
"my_index": {
"mappings": {
"my_doctype": {
"properties": {
"@timestamp": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"@version": {
"type": "string"
},
"prod_id": {
"type": "string"
},
"host": {
"type": "string"
},
"message": {
"type": "string"
},
"path": {
"type": "string"
},
"img_path": {
"type": "string"
},
"tags": {
"type": "string"
}
}
}
}
}
}

我试图将某些字段从 analyzed更改为 non_analyzed,所以我运行了此请求:
PUT my_index/_mapping/my_doctype 
{
"properties": {
"prod_id": {
"type": "string",
"index": "not_analyzed"
},
"img_path": {
"type": "string",
"index": "not_analyzed"
}
}
}

但是我收到以下错误:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Mapper for [img_path] conflicts with existing mapping in other types:\n[mapper [img_path] has different [index] values, mapper [img_path] has different [doc_values] values, cannot change from disabled to enabled, mapper [img_path] has different [analyzer], mapper [img_path] is used by multiple types. Set update_all_types to true to update [omit_norms] across all types., mapper [img_path] is used by multiple types. Set update_all_types to true to update [search_analyzer] across all types., mapper [img_path] is used by multiple types. Set update_all_types to true to update [search_quote_analyzer] across all types.]"
}
],
"type": "illegal_argument_exception",
"reason": "Mapper for [img_path] conflicts with existing mapping in other types:\n[mapper [img_path] has different [index] values, mapper [img_path] has different [doc_values] values, cannot change from disabled to enabled, mapper [img_path] has different [analyzer], mapper [img_path] is used by multiple types. Set update_all_types to true to update [omit_norms] across all types., mapper [img_path] is used by multiple types. Set update_all_types to true to update [search_analyzer] across all types., mapper [img_path] is used by multiple types. Set update_all_types to true to update [search_quote_analyzer] across all types.]"
},
"status": 400
}

如何将字段“prod_id”和“img_path”更改为 not_analyzed

最佳答案

您不能更改现有字段的映射。您有两种解决方案:

  • 您可以删除索引,使用正确的映射重新创建索引,然后为数据重新索引
  • 您可以创建not_analyzed子字段并为数据重新索引

  • 第二种解决方案是这样的:
    PUT my_index/_mapping/my_doctype 
    {
    "properties": {
    "prod_id": {
    "type": "string",
    "fields": {
    "raw": {
    "type": "string",
    "index": "not_analyzed"
    }
    }
    },
    "img_path": {
    "type": "string",
    "fields": {
    "raw": {
    "type": "string",
    "index": "not_analyzed"
    }
    }
    }
    }
    }

    重新索引数据后,可以使用 prod_id.rawimg_path.raw

    关于elasticsearch - 无法在ElasticSearch中将映射更改为non_analyzed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40724887/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com