【问题标题】:Reindex multiple types from one index to single type in another index将多个类型从一个索引重新索引为另一个索引中的单个类型
【发布时间】:2017-09-01 06:21:05
【问题描述】:

我有两个索引: 推特和reitwitter

twitter 有多个不同类型的文档,例如:

"hits": [
{
"_index": "twitter",
"_type": "tweet",
"_id": "1",
"_score": 1,
"_source": {
"message": "trying out Elasticsearch"
}
},
{
"_index": "twitter",
"_type": "tweet2",
"_id": "1",
"_score": 1,
"_source": {
"message": "trying out Elasticsearch2"
}
},
{
"_index": "twitter",
"_type": "tweet1",
"_id": "1",
"_score": 1,
"_source": {
"message": "trying out Elasticsearch1"
}
}
]

现在,当我重新索引时,我想摆脱所有不同的类型,只使用一种,因为它们本质上具有相同的字段映射。

我尝试了几种不同的组合,但我总是只得到一个文档而不是这三个: 方法一:

POST _reindex/
{
"source": {
"index": "twitter"
}
,
"dest": {
"index": "reitwitter",
"type": "reitweet"
}
}

回复:

{
"took": 12,
"timed_out": false,
"total": 3,
"updated": 3,
"created": 0,
"deleted": 0,
"batches": 1,
"version_conflicts": 0,
"noops": 0,
"retries": {
"bulk": 0,
"search": 0
},
"throttled_millis": 0,
"requests_per_second": -1,
"throttled_until_millis": 0,
"failures": []
}

注意:它说更新了 3,因为我猜这是我第二次拨打相同的电话?

第二种方法:

POST _reindex/
{
"source": {
"index": "twitter",
"query": {
"match_all": {
}
}
}
,
"dest": {
"index": "reitwitter",
"type": "reitweet"
}
}

与第一个响应相同。

在这两种情况下,当我进行 GET 调用时:

GET reitwitter/_search
{
"query": {
"match_all": {
}
}
}

我只得到一份文件:

{
"_index": "reitwitter",
"_type": "reitweet",
"_id": "1",
"_score": 1,
"_source": {
"message": "trying out Elasticsearch1"
}

reindex 是否支持这个用例?如果没有,我是否必须使用扫描和滚动编写脚本以从源索引中获取所有文档并在目标中使用相同的文档类型重新索引它们?

PS:我不想使用 "_source": ["tweet1", "tweet"] 因为我有大约百万个文档类型,每个文档类型都有一个文档,我想映射到目标中的相同文档类型.

【问题讨论】:

    标签: elasticsearch reindex elasticsearch-mapping


    【解决方案1】:

    问题是所有文档都有相同的 id(1),然后它们在重新索引过程中覆盖了自己。

    尝试使用不同的 id 为您的文档编制索引,您会发现它有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-11
      • 1970-01-01
      • 2021-04-05
      • 2013-04-16
      • 2013-01-06
      • 2018-09-01
      • 1970-01-01
      • 2015-08-07
      相关资源
      最近更新 更多