从现有索引创建的新索引中缺少 elasticsearch 文档

时间:2021-04-19 11:35:36

标签: elasticsearch

我有一个名为“prod.custom.historical.actions-2021-03”的现有索引,并创建了一个名为“PUT /prod.custom.historical.actions-2021-04-19”的新索引

以相同的顺序执行下面的命令。 PUT /prod.custom.historical.actions-2021-04-19

POST _reindex
{
  "source": {
    "index": "prod.custom.historical.tasks-2021-03"
  },
  "dest": {
    "index": "prod.custom.historical.tasks-2021-04-19"
  }
}

GET /prod.custom.historical.actions-2021-03/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "projectId": [
              "73ef9fa8-6665-4cbb-881c-4663030a7d45"
            ]
          }
        }
      ]
    }
  }
}

返回

"took" : 5,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 93,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [


GET /prod.custom.historical.actions-2021-04-19/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "projectId": [
              "73ef9fa8-6665-4cbb-881c-4663030a7d45"
            ]
          }
        }
      ]
    }
  }
}

返回

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  }
}

这清楚地表明缺少文件,有人可以在这里帮助我理解问题。

1 个答案:

答案 0 :(得分:1)

在 reindex API 中,只有文档从一个索引复制到另一个索引。需要配置新索引的映射,如官方documentation

中所述 <块引用>

在调用之前应根据需要配置目的地 _重新索引。 Reindex 不会从源或其关联模板复制设置。

映射、分片计数、副本等必须提前配置 时间。

如果您没有为索引 "prod.custom.historical.actions-2021-04-19" 明确定义任何映射,那么您需要将 .keyword 添加到 projectId 字段。这使用关键字分析器而不是标准分析器(注意 projectId 字段后面的“.keyword”)。

GET /prod.dhl.historical.actions-2021-04-19/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "projectId.keyword": [            // note this
              "73ef9fa8-6665-4cbb-881c-4663030a7d45"
            ]
          }
        }
      ]
    }
  }
}