Hive外表关联es,数据未更新问题
问题:
insert overwrite es_hive_table select * from hive_table ,这样的语句,es_hive_table是hive外表关联了es 配置,hive_table的id= 1 的db_topic更新了,为什么es_hive_table 表中id= 1 的db_topic并没有更新呢?
分析:
es_hive_table是一个外部表(External Table),其与Elasticsearch进行关联。对于外部表,Hive只负责管理元数据(metadata),而实际的数据存储在外部系统中,例如Elasticsearch。当你执行insert overwrite es_hive_table select * from hive_table语句时,Hive会从hive_table中选择所有行,并将其覆盖写入到es_hive_table中。但是,这个操作只影响Hive的元数据,并不会自动更新Elasticsearch中的数据。如果你想要实现数据的同步更新,你需要确保在Hive外部表与Elasticsearch之间设置了适当的同步机制。这可能涉及到使用工具、编写脚本或配置相关的ETL(抽取、转换和加载)流程来使得数据在Hive和Elasticsearch之间保持同步。
所以,如果es_hive_table中的db_topic字段没有更新,可能是因为缺乏相应的同步机制来确保数据的同步更新。你需要检查你的环境和配置,确保正确地设置了数据同步。
解决:
自己的表没有同步更新数据的设置和环境,因此查询并修改es数据
GET /metadata_map/_search
{
"aggs": {
"distinct_topics": {
"terms": {
"field": "db_topic.keyword",
"size": 1000
}
}
}
}
-- 单值查询
GET /metadata_map/_search
{
"query": {
"term": {
"db_topic": {
"value": "某某"
}
}
}
}
-- 多值查询
GET /metadata_map/_search
{
"query": {
"terms": {
"id": [
"dwd_dwd_table1",
"dwd_dwd_table2",
"dwd_dwd_table3"
]
}
}
}
-- 依次更新
POST metadata_map/_doc/dwd_dwd_test_table/_update
{
"doc":{
"db_topic":"new_value"
}
}
-- 更新语句模版
POST ${index_name}/${_doc}/${_id}/_update
{
"doc" : {
"field_name" : field_value
}
}
-- 查询db_topic个数
GET /metadata_map/_search
{
"aggs": {
"count_emp": {
"cardinality": {
"field": "db_topic.keyword"
}
}
}
}
-- 第一步复制index
POST _reindex
{
"source": {
"index": "metadata_map"
},
"dest": {
"index": "metadata_map_0711",
"op_type": "create"
}
}

浙公网安备 33010602011771号