gpt4 book ai didi

elasticsearch - Elasticsearch Reindex API不起作用

转载 作者:行者123 更新时间:2023-12-02 22:24:04 26 4
gpt4 key购买 nike

我正在尝试使用reindex API进行Elasticsearch

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

这是我的来源索引

"testtype": {
"_all": {
"enabled": false
},
"dynamic_templates": [
{
"message_field": {
"mapping": {
"fielddata": {
"format": "disabled"
},
"index": "analyzed",
"omit_norms": true,
"type": "string"
},
"match": "message",
"match_mapping_type": "string"
}
},
{
"string_fields": {
"mapping": {
"fielddata": {
"format": "disabled"
},
"index": "analyzed",
"omit_norms": true,
"type": "string",
"fields": {
"raw": {
"ignore_above": 256,
"index": "not_analyzed",
"type": "string"
}
}
},
"match": "*",
"match_mapping_type": "string"
}
}
],
"properties": {
"@timestamp": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"@version": {
"type": "string",
"index": "not_analyzed"
},
"app_code": {
"type": "string"
},
"data": {
"properties": {
"action": {
"type": "string",
"norms": {
"enabled": false
},
"fielddata": {
"format": "disabled"
},
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed",
"ignore_above": 256
}
}
},
"level": {
"type": "string",
"norms": {
"enabled": false
},
"fielddata": {
"format": "disabled"
},
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed",
"ignore_above": 256
}
}
},
"message": {
"type": "string",
"norms": {
"enabled": false
},
"fielddata": {
"format": "disabled"
}
},
"timestamp": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
}
}
},
"header": {
"properties": {
"@timestamp": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"_id": {
"type": "long"
},
"app_code": {
"type": "string",
"norms": {
"enabled": false
},
"fielddata": {
"format": "disabled"
},
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed",
"ignore_above": 256
}
}
},
"host": {
"type": "string",
"norms": {
"enabled": false
},
"fielddata": {
"format": "disabled"
},
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed",
"ignore_above": 256
}
}
},
"meta_host": {
"type": "string",
"norms": {
"enabled": false
},
"fielddata": {
"format": "disabled"
},
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed",
"ignore_above": 256
}
}
},
"name": {
"type": "string",
"norms": {
"enabled": false
},
"fielddata": {
"format": "disabled"
},
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed",
"ignore_above": 256
}
}
},
"pid": {
"type": "long"
},
"source_id": {
"type": "string",
"norms": {
"enabled": false
},
"fielddata": {
"format": "disabled"
},
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed",
"ignore_above": 256
}
}
},
"source_name": {
"type": "string",
"norms": {
"enabled": false
},
"fielddata": {
"format": "disabled"
},
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed",
"ignore_above": 256
}
}
},
"timestamp": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"user": {
"type": "string",
"norms": {
"enabled": false
},
"fielddata": {
"format": "disabled"
},
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed",
"ignore_above": 256
}
}
}
}
},
"source_id": {
"type": "string"
},
"timestamp": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
}
}
}

因此,它具有一些 string字段,这些字段也具有相应的原始字段。问题在于默认字段是 analyzed。所以我希望新索引是
{
"mappings": {
"test": {
"dynamic_templates": [
{ "notanalyzed": {
"match": "*",
"path_unmatch":"data.message",
"match_mapping_type": "string",
"mapping": {
"type": "string",
"index": "not_analyzed",
"fielddata": {
"format": "disabled"
},
"fields": {
"raw": {
"ignore_above": 256,
"index": "not_analyzed",
"type": "string"
}
}
}
}
}
]
}
}
}

旧索引有一些数据。所以我试图重新索引为
POST /_reindex
{
"source": {
"index": "oldindex",
"type": ["testtype"]
},
"dest": {
"index": "newindex"
}
}

执行完此操作后,我看到新索引已转换为
{
"newindex": {
"aliases": {},
"mappings": {
"testtype": {
"properties": {
"data": {
"properties": {
"action": {
"type": "string"
},
"level": {
"type": "string"
},
"message": {
"type": "string"
},
"timestamp": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
}
}
},
"header": {
"properties": {
"@timestamp": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"_id": {
"type": "long"
},
"app_code": {
"type": "string"
},
"host": {
"type": "string"
},
"meta_host": {
"type": "string"
},
"name": {
"type": "string"
},
"pid": {
"type": "long"
},
"source_id": {
"type": "string"
},
"source_name": {
"type": "string"
},
"timestamp": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"user": {
"type": "string"
}
}
}
}
},
"test": {
"dynamic_templates": [
{
"notanalyzed": {
"mapping": {
"fielddata": {
"format": "disabled"
},
"index": "not_analyzed",
"type": "string",
"fields": {
"raw": {
"ignore_above": 256,
"index": "not_analyzed",
"type": "string"
}
}
},
"match": "*",
"match_mapping_type": "string",
"path_unmatch": "data.message"
}
}
]
}
},
"settings": {
"index": {
"creation_date": "1461792130202",
"number_of_shards": "5",
"number_of_replicas": "1",
"uuid": "nho7V2PpTbqzfsUVWVdLkA",
"version": {
"created": "2030099"
}
}
},
"warmers": {}
}
}

我不明白这里发生了什么!看来新数据只是自动索引了!这根本不是我想要的。

我什至试过
POST /_reindex
{
"source": {
"index": "oldindex",
"type": ["testtype"]
},
"dest": {
"index": "newindex",
"type": ["test"]
}
}

但现在我明白了
{
"error": "org.elasticsearch.ElasticsearchParseException: Unknown array field [type]"
}

我究竟做错了什么?我不能使用elasticdump或背包,因为它们是第三方插件。

最佳答案

你快到了。

  • 删除错误创建的索引:DELETE newindex
  • 创建newindex索引:

  • PUT /newindex
    {
    "mappings": {
    "test": {
    "dynamic_templates": [
    {
    "notanalyzed": {
    "match": "*",
    "path_unmatch": "data.message",
    "match_mapping_type": "string",
    "mapping": {
    "type": "string",
    "index": "not_analyzed",
    "fielddata": {
    "format": "disabled"
    },
    "fields": {
    "raw": {
    "ignore_above": 256,
    "index": "not_analyzed",
    "type": "string"
    }
    }
    }
    }
    }
    ]
    }
    }
    }
  • 并使用此经过稍微修改的_reindex命令:

  • POST /_reindex
    {
    "source": {
    "index": "oldindex",
    "type": [
    "testtype"
    ]
    },
    "dest": {
    "index": "newindex"
    },
    "script": {
    "inline": "ctx._type='test'"
    }
    }

    重要的是 script,您在其中告诉 _reindex API更改 _type中文档的 newindex

    关于elasticsearch - Elasticsearch Reindex API不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36901343/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com