ElasticSearh更新nested字段(Array數組)。怎么根據查詢條件(query)復制一個(index)到新的Index how to update by query a nested fields data for elasticsearch


GET usernested/_search
{
  "query": {
    "nested": {
      "path": "tags",
      "query": {
        "bool": {
          "must": [
            {
              "term": {
                "tags.brandid": "93a8296c-5b64-49ea-bd92-b19192def2e9"
              }
            },
            {
              "term": {
                "tags.site": "163"
              }
            }
          ]
        }
      }
    }
  }
}


//按照條件新建一個index 作為測試數據使用
POST _reindex
{
  "source": {
    "index": "usernested",
    "query": {
      "nested": {
        "path": "tags",
        "query": {
          "bool": {
            "must": [
              {
                "term": {
                  "tags.brand": "c55fd643-1333-4647-b898-fb3e5e4e6d67"
                }
              },
              {
                "term": {
                  "tags.site": "163"
                }
              }
            ]
          }
        }
      }
    }
  },
  "dest": {
    "index": "new_usernested"
  }
}


//查詢
GET new_usernested/_search
{
  "query": {
    "nested": {
      "path": "tags",
      "query": {
        "bool": {
          "must": [
            {
              "term": {
                "tags.brand": "c55fd643-1333-4647-b898-fb3e5e4e6d67"
              }
            },
            {
              "term": {
                "tags.site": "163"
              }
            }
          ]
        }
      }
    }
  }
}

//根據條件更新一個 nested的文檔
GET usernested/_update_by_query
{
  "query": {
    "nested": {
      "path": "tags",
      "query": {
        "bool": {
          "must": [
            {
              "term": {
                "tags.brand": "c55fd643-1333-4647-b898-fb3e5e4e6d67"
              }
            },
            {
              "term": {
                "tags.site": "163"
              }
            }
          ]
        }
      }
    }
  },
  "script": {
    "inline": "for(e in ctx._source.tags){e.brand = 'test2';}" //更新nested字段
//"inline":"ctx._source.userid = 'testid'" //更新普通字段 } }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM