elasticsearch-hadoophive導(dǎo)入數(shù)據(jù)怎么實(shí)現(xiàn)不自動(dòng)分詞

這篇文章主要講解了“elasticsearch-hadoop hive導(dǎo)入數(shù)據(jù)怎么實(shí)現(xiàn)不自動(dòng)分詞”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“elasticsearch-hadoop hive導(dǎo)入數(shù)據(jù)怎么實(shí)現(xiàn)不自動(dòng)分詞”吧!

通城ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書(shū)未來(lái)市場(chǎng)廣闊!成為成都創(chuàng)新互聯(lián)公司的ssl證書(shū)銷(xiāo)售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話(huà)聯(lián)系或者加微信:13518219792(備注:SSL證書(shū)合作)期待與您的合作!

背景

基于本公司使用es場(chǎng)景,不需要分詞功能.而es string 類(lèi)型的時(shí)候,會(huì)自動(dòng)分詞,導(dǎo)致省份、地區(qū)等字段都分詞了。

具體使用方式

  1. 創(chuàng)建 elasticsearc 模板(_template),使用命令:

curl -XPUT localhost:9200/_template/dmp_down_result -d '  

{  

    "template" : "dmp_down_*",  #定義模板名字,以dmp_down_ 開(kāi)始的索引將使用此模板

    "settings": { 

        "number_of_shards": 14, #設(shè)置分片數(shù)量

        "number_of_replicas": 1, #設(shè)置副本數(shù)

        "index.refresh_interval": "30s" #刷新間隔(可不設(shè)置)

    },

   "aliases" : {  

        "dmp_down_result" : {}    #別名

    },

    "mappings" : {  

    "dmp_es_result1":{ #索引中的type名字,需要與被建索引一致

          "properties": #具體字段映射設(shè)置

                {"user_id": { #hive數(shù)據(jù)中的字段,必須與此對(duì)應(yīng)

                    "type" : "multi_field", #類(lèi)型  多媒體

                   "fields" : {

                    "user_id" : {"type" : "string", "index" : "not_analyzed"} , #類(lèi)型  string,not_analyzed:為不使用分詞,使用分詞為:analyzed

                    }

                },

"phone": {

                    "type" : "multi_field",

                   "fields" : {

                    "imei" : {"type" : "string", "index" : "not_analyzed"}

                    }

                },

"address": {

                    "type" : "multi_field",

                   "fields" : {

                    "idfa" : {"type" : "string", "index" : "not_analyzed"}

                    }

                }

                }

            }}

          }

    }  

}  '  

創(chuàng)建完模板后,可通過(guò)http://localhost:9200/_template 來(lái)查看是否生效

由此完成創(chuàng)建操作.下附圖


elasticsearch-hadoop hive導(dǎo)入數(shù)據(jù)怎么實(shí)現(xiàn)不自動(dòng)分詞

導(dǎo)入數(shù)據(jù)如報(bào):maybe it contains illegal characters? 此錯(cuò)誤時(shí),在導(dǎo)入時(shí)是無(wú)法排查的,可通過(guò)手動(dòng)創(chuàng)建索引/type 方式來(lái)查看具體錯(cuò)誤信息.如:{"error":{"root_cause":[{"type":"remote_transport_exception","reason":"[dmp_es-16][10.8.1.16:9300][indices:admin/create]"}],"type":"illegal_state_exception","reason":"index and alias names need to be unique, but alias [dmp_keyword_result] and index [dmp_keyword_result] have the same name"},"status":500} 這樣可以更直觀的看出問(wèn)題.索引名重復(fù),重新啟一個(gè)索引名字就可以了.

附:es-hadoop hive數(shù)據(jù)同步方法:

  1. 下載eslaticsearch-hadoop jar包,需要與當(dāng)前elasticsearch 版本相對(duì)應(yīng)

  2. 將eslaticsearch-hadoop jar上傳到集群

  3. 在hive命令行中 執(zhí)行:add jar /home/hdroot/ elasticsearch-hadoop-2.2.0.jar

  4. 建表命令:

CREATE EXTERNAL TABLE dmp_es_result2(

  user_id string, 

  imei string, 

  idfa string, 

  email string, 

  type_id array<string>, 

  province string, 

  region string, 

  dt string, 

  terminal_brand string, 

  system string)

STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'   

TBLPROPERTIES('es.resource' = '索引名/類(lèi)型',

'es.index.auto.create' = 'true',

'es.nodes'='localhost',

'es.port' = '9200',

'es.field.read.empty.as.null' ='true');

es.resource:指定同步到es 中的索引名/類(lèi)型名

es.index.auto.create:是否使用主動(dòng)主鍵,如不使用可指定es.mapping.id=主鍵

es.nodes:es集群節(jié)點(diǎn)地址,任意一個(gè)節(jié)點(diǎn)就可以,多個(gè)可以用逗號(hào)(,)分開(kāi)如:192.168.1.1:9200,192.168.1.2:9200 

es.port:es集群端口號(hào),如es.nodes指定了多個(gè),此可以不使用

es.field.read.empty.as.null:對(duì)空、null字段的處理方式。加上此參數(shù)可以使數(shù)據(jù)導(dǎo)入更準(zhǔn)備(此處有點(diǎn)不太確定)

導(dǎo)入數(shù)據(jù)hive語(yǔ)句:

INSERT OVERWRITE TABLE dmp_es_result2 select user_id,imei,idfa,email,type_id,province,region,dt,terminal_brand,system from temp_zy_game_result01;

如果執(zhí)行成功,就可以看到es中的數(shù)據(jù)同步過(guò)去了.

感謝各位的閱讀,以上就是“elasticsearch-hadoop hive導(dǎo)入數(shù)據(jù)怎么實(shí)現(xiàn)不自動(dòng)分詞”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)elasticsearch-hadoop hive導(dǎo)入數(shù)據(jù)怎么實(shí)現(xiàn)不自動(dòng)分詞這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

新聞名稱(chēng):elasticsearch-hadoophive導(dǎo)入數(shù)據(jù)怎么實(shí)現(xiàn)不自動(dòng)分詞
新聞來(lái)源:http://muchs.cn/article18/jchggp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、外貿(mào)網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)網(wǎng)站建設(shè)、網(wǎng)站改版

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化