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

cyb*_*oof 48 elasticsearch

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

curl -XPUT "http://192.168.0.2:9200/movies/movie/1" -d'
{
    "title": "The Godfather",
    "director": "Francis Ford Coppola",
    "year": 1972
}'
Run Code Online (Sandbox Code Playgroud)

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

Lud*_*ord 105

从ElasticSearch 2.3开始,您现在可以使用内置_reindexAPI

例如:

POST /_reindex
{
  "source": {
    "index": "twitter"
  },
  "dest": {
    "index": "new_twitter"
  }
}
Run Code Online (Sandbox Code Playgroud)

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

POST /_reindex
{
  "source": {
    "index": "twitter",
    "query": {
      "term": {
        "user": "kimchy"
      }
    }
  },
  "dest": {
    "index": "new_twitter"
  }
}
Run Code Online (Sandbox Code Playgroud)

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

  • 请注意,它不会复制映射和设置(例如,如果您的字段设置总数大于默认值 1000)。在这种情况下,您应该使用设置创建一个新索引,然后运行 ​​_reindex。请参阅:https://www.elastic.co/guide/en/elasticsearch/reference/5.4/docs-reindex.html#docs-reindex (5认同)
  • AFAIK,目标索引必须预先配置 *mappings* (3认同)

KWu*_*icz 47

最好的方法是使用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
Run Code Online (Sandbox Code Playgroud)


cof*_*ict 5

查看背包:https: //github.com/jprante/elasticsearch-knapsack

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

curl -XPOST 'localhost:9200/test/test/_export' -d '{
"query" : {
    "match" : {
        "myfield" : "myvalue"
    }
},
"fields" : [ "_parent", "_source" ]
}'
Run Code Online (Sandbox Code Playgroud)

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


Ram*_*nti 5

将特定类型从源索引重新索引到目标索引类型的语法是

POST _reindex/
 {
 "source": {
 "index": "source_index",
 "type": "source_type",
 "query": {
  // add filter criteria
   }
 },
 "dest": {
  "index": "dest_index",
  "type": "dest_type"
  }
}
Run Code Online (Sandbox Code Playgroud)