0

我有两个索引:twitter 和 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"
}
}
]

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

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

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"] 因为我有大约百万个文档类型,每个文档类型都有一个文档,我想映射到目标中的相同文档类型。

4

1 回答 1

0

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

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

于 2017-08-31T21:34:57.237 回答