gpt4 book ai didi

elasticsearch - 如何在不破坏Elasticsearch中数据的情况下更改架构?

转载 作者:行者123 更新时间:2023-12-03 00:57:09 25 4
gpt4 key购买 nike

这是我目前的模式

{
"mappings": {
"historical_data": {
"properties": {
"continent": {
"type": "string",
"index": "not_analyzed"
},
"country": {
"type": "string",
"index": "not_analyzed"
},
"description": {
"type": "string"
},
"funding": {
"type": "long"
},
"year": {
"type": "integer"
},
"agency": {
"type": "string"
},
"misc": {
"type": "string"
},
"university": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}

我上传了70万条记录。在不破坏数据的情况下,如何使大学索引不被“not_analysed”,以使更改反射(reflect)在现有数据中?

最佳答案

现有字段的映射无法修改。
但是,您可以通过两种方式实现所需的结果。

  • 创建另一个字段。使用put _mapping API
  • 免费添加字段

    curl -XPUT localhost:9200/YOUR_INDEX/_mapping -d '{
    "properties": {
    "new_university": {
    "type": "string"
    }
    }
    }'

  • 使用multi-fields,将一个子字段添加到not_analyzed字段中。

  • curl -XPUT localhost:9200/YOUR_INDEX/_mapping -d '{
    "properties": {
    "university": {
    "type": "string",
    "index": "not_analyzed",
    "fields": {
    "university_analyzed": {
    "type": "string" // <-- ANALYZED sub field
    }
    }
    }
    }
    }'


    在这两种情况下,都需要重新索引以便填充新字段。使用 _reindex API
    curl -XPUT localhost:9200/_reindex -d '{
    "source": {
    "index": "YOUR_INDEX"
    },
    "dest": {
    "index": "YOUR_INDEX"
    },
    "script": {
    "inline": "ctx._source.university = ctx._source.university"
    }
    }'

    关于elasticsearch - 如何在不破坏Elasticsearch中数据的情况下更改架构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42711865/

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