如何将一些ElasticSearch数据复制到新索引

 WINGZERO哥哥 发布于 2022-12-29 20:19

假设我的ElasticSearch中有电影数据,我就像这样创建它们:

curl -XPUT "http://192.168.0.2:9200/movies/movie/1" -d'
{
    "title": "The Godfather",
    "director": "Francis Ford Coppola",
    "year": 1972
}'

我有一堆不同年代的电影.我想所有的电影从某个特定年份(因此,1972年),复制并拷贝到"70sMovies"的新指标,但我看不出如何做到这一点.

3 个回答
  • 查看背包:https: //github.com/jprante/elasticsearch-knapsack

    一旦安装并运行了插件,就可以通过查询导出部分索引.例如:

    curl -XPOST 'localhost:9200/test/test/_export' -d '{
    "query" : {
        "match" : {
            "myfield" : "myvalue"
        }
    },
    "fields" : [ "_parent", "_source" ]
    }'
    

    这将仅使用您的查询结果创建一个tarball,然后您可以将其导入另一个索引.

    2022-12-29 20:21 回答
  • 最好的方法是使用elasticsearch-dump工具https://github.com/taskrabbit/elasticsearch-dump.

    我使用的现实世界的例子:

    elasticdump \
      --input=http://localhost:9700/.kibana \
      --output=http://localhost:9700/.kibana_read_only \
      --type=mapping
    elasticdump \
      --input=http://localhost:9700/.kibana \
      --output=http://localhost:9700/.kibana_read_only \
      --type=data
    

    2022-12-29 20:21 回答
  • 从ElasticSearch 2.3开始,您现在可以使用内置_reindexAPI

    例如:

    POST /_reindex
    {
      "source": {
        "index": "twitter"
      },
      "dest": {
        "index": "new_twitter"
      }
    }
    

    或者只通过添加过滤器/查询来指定特定部分

    POST /_reindex
    {
      "source": {
        "index": "twitter",
        "query": {
          "term": {
            "user": "kimchy"
          }
        }
      },
      "dest": {
        "index": "new_twitter"
      }
    }
    

    阅读更多:https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html

    2022-12-29 20:21 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有