elasticsearch 在elasticsearch中重新命名字段名称,elasticsearch,lucene,elasticsearch,Lucene" /> elasticsearch 在elasticsearch中重新命名字段名称,elasticsearch,lucene,elasticsearch,Lucene" />

elasticsearch 在elasticsearch中重新命名字段名称

elasticsearch 在elasticsearch中重新命名字段名称,elasticsearch,lucene,elasticsearch,Lucene,我试图在弹性搜索中重命名字段名,下面是示例数据,其中我需要更改部分/所有字段名以及嵌套对象 { "took": 63, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 1000, "max_score": 1,

我试图在弹性搜索中重命名字段名,下面是示例数据,其中我需要更改部分/所有字段名以及嵌套对象

{   
   "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\")"  

  }  }   
但是这个解决方案将只重命名/修改一个字段(甚至不是嵌套字段),如何重命名弹性搜索索引中的多个/所有上述字段


感谢您的快速响应并感谢您的快速响应

重命名最简单的方法是使用\u update\u by\u查询API:

例如:

"_source": {  
           "quantity": 25,  
           "price": "137.62",  
           "name": "Veal - Leg",
           "categories": [  
              {   
                 "name": "Sport"  
              },  
              {  
                 "name": "Clothing"  
              }  
           ] 
        }  
重命名categories.namecategories.categoryName

发布http://localhost:9200/INDEX_NAME/_update_by_query

{
  "query": { 
    "bool": {
        "must_not": {
            "exists": {
                "field": "categoryName"
            }
        }
    }
  },
  "script" : {
    "inline": "ctx._source.categories.categoryName= ctx._source.categories.name; ctx._source.categories.remove(\"name\");"
  }
}

请解释/突出显示您要修改的其他字段。您可能需要重新编制索引。我想将“描述”改为“描述”,将“价格”改为“成本”,将“类别.名称”改为“类别.名称”--如Elasticsearch 7.1.11中的“内联改为源代码”
“**source**”:“ctx.\u source.categories.categoriName=ctx.\u source.categories.name;ctx.\u source.categories.remove(\“name\”)”