我正在尝试重命名ElasticSearch中的文件名,下面是示例数据,其中我需要更改一些/所有字段名和嵌套对象
{
"took": 63,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1000,
"max_score": 1,
"hits": [
{
"_index": "course",
"_type": "product",
"_id": "14",
"_score": 1,
"_source": {
"quantity": 25,
"price": "137.62",
"name": "Veal - Leg",
"description": "Morbi non lectus. Aliquam sit amet diam in magna bibendum imperdiet. Nullam orci pede, venenatis non, sodales sed, tincidunt eu, felis. Fusce posuere felis sed lacus. Morbi sem mauris, laoreet ut, rhoncus aliquet, pulvinar sed, nisl. Nunc rhoncus dui vel sem.",
"categories": [
{
"name": "Sport"
},
{
"name": "Clothing"
}
],
"tagNames": [
"phones",
"elasticsearch"
],
"status": "inactive"
}
}
}
现在我想用新的字段名重命名所有上述现有字段我尝试过这个解决方案
POST /_reindex
{
"source": {
"index": "course"
},
"dest": {
"index": "course_new"
},
"script": {
"inline": "ctx._source.tags = ctx._source.remove(\"tagNames\")"
} }
但是这个解决方案只会重命名/修改一个字段(甚至不是嵌套的字段),我如何在ElasticSearch索引中重命名多个/所有上述字段。
感谢您的快速响应,并感谢您的快速响应
1条答案
按热度按时间vdgimpew1#
重命名*字段名称的最简单方法是使用**_update_by_query**API:
示例:
将categories.name重新命名为categories.categoryName
POSThttp://localhost:9200/INDEX_NAME/_update_by_query(通过查询更新)