【问题标题】:How do I apply reindex to new data values through filters?如何通过过滤器将重新索引应用于新数据值?
【发布时间】:2021-08-03 09:25:12
【问题描述】:

这是 basic_data(example) 输出值

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 163,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "0513_final_test_instgram",
        "_type" : "_doc",
        "_id" : "6uShY3kBEkIlakOYovrR",
        "_score" : 1.0,
        "_source" : {
          "host" : "DESKTOP-7MDCA36",
          "path" : "C:/python_file/20210513_114123_instargram.csv",
          "@version" : "1",
          "message" : "hello",
          "@timestamp" : "2021-05-13T02:50:05.962Z"
        },
      {
        "_index" : "0513_final_test_instgram",
        "_type" : "_doc",
        "_id" : "EeShY3kBEkIlakOYovvm",
        "_score" : 1.0,
        "_source" : {
          "host" : "DESKTOP-7MDCA36",
          "path" : "C:/python_file/20210513_114123_instargram.csv",
          "@version" : "1",
          "message" : "python,
          "@timestamp" : "2021-05-13T02:50:05.947Z"
        }

首先,出各种字段值,only message values have been extracted.(代码示例下)

GET 0513_final_test_instgram/_search?_source=message&filter_path=hits.hits._source
{
  "hits" : {
    "hits" : [
      {
        "_source" : {
          "message" : "hello"
        }
      },
      {
        "_source" : {
          "message" : "python"
        }

我认识了存储新索引的reindex

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

但是,我看文档也不知道。

0513 尝试代码

POST _reindex
{
  "source": {
    "index": "0513_final_test_instgram"
  },
  "dest": {
    "index": "new_data_index"
  }
}

如何使用 reindex 将仅提取消息值的数据存储在新索引中?

更新评论尝试

output

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 163,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "new_data_index",
        "_type" : "_doc",
        "_id" : "6uShY3kBEkIlakOYovrR",
        "_score" : 1.0,
        "_source" : {
          "message" : "hello"
        }
      },
      {
        "_index" : "new_data_index",
        "_type" : "_doc",
        "_id" : "EeShY3kBEkIlakOYovvm",
        "_score" : 1.0,
        "_source" : {
          "message" : "python"
        }
      }

【问题讨论】:

    标签: elasticsearch kibana querydsl


    【解决方案1】:

    你只需要specify which fields你想重新索引到新索引:

    {
      "source": {
        "index": "0513_final_test_instgram",
        "_source": ["message"]
      },
      "dest": {
        "index": "new_data_index"
      }
    }
    

    【讨论】:

    • 字段中,不能去掉_index,_type,_id, and_score
    • 有什么办法只保存_source > 消息值?
    • _index、_type 和 _id 不是您文档的一部分,它们是元字段,它们将永远存在。您可以在目标索引上应用与在源索引上相同的 filter_path。
    • 那你不能擦除元字段值吗?我不明白。请给我代码。如何才能看到只存储了消息字段的值?
    • 您的文档进入_source(这是您唯一可以影响的内容)。 _index_id 是由 ES 管理的字段,您不能删除它们(这样做没有意义)。但是,当您可以像查询旧索引一样查询新索引时,即GET new_data_index/_search?_source=message&filter_path=hits.hits._source
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-21
    • 1970-01-01
    • 2021-07-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多