elasticsearch7.x-reindex

同一集群条件查询一个索引的数据插入到另一个索引

限制条件:指定需要的字段及确定的返回数据条数

示例:

POST _reindex
{
  "size": 5,
  "source": {
    "index": "movies",
    "_source": [
      "genre",
      "title"
    ],
    "sort": {
      "genre.keyword": "desc"
    },
    "query": {
      "match": {
        "title": "Dracula"
      }
    }
  },
  "dest": {
    "index": "reindex_20210306"
  }
}

结果:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 5,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "reindex_20210306",
        "_type" : "_doc",
        "_id" : "1339",
        "_score" : 1.0,
        "_source" : {
          "genre" : [
            "Fantasy",
            "Horror",
            "Romance",
            "Thriller"
          ],
          "title" : "Dracula"
        }
      },
      {
        "_index" : "reindex_20210306",
        "_type" : "_doc",
        "_id" : "6665",
        "_score" : 1.0,
        "_source" : {
          "genre" : [
            "Horror",
            "Romance"
          ],
          "title" : "Dracula"
        }
      },
      {
        "_index" : "reindex_20210306",
        "_type" : "_doc",
        "_id" : "2653",
        "_score" : 1.0,
        "_source" : {
          "genre" : [
            "Horror"
          ],
          "title" : "Son of Dracula"
        }
      },
      {
        "_index" : "reindex_20210306",
        "_type" : "_doc",
        "_id" : "2644",
        "_score" : 1.0,
        "_source" : {
          "genre" : [
            "Horror"
          ],
          "title" : "Dracula"
        }
      },
      {
        "_index" : "reindex_20210306",
        "_type" : "_doc",
        "_id" : "4030",
        "_score" : 1.0,
        "_source" : {
          "genre" : [
            "Horror"
          ],
          "title" : "Dracula 2000"
        }
      }
    ]
  }
}

官方地址:https://www.elastic.co/guide/en/elasticsearch/reference/7.2/docs-reindex.html

posted on 2021-03-21 18:51  0x153_小波  阅读(49)  评论(0编辑  收藏  举报