已经搭建好了IK中文分词环境.
http://blog.itpub.net/29254281/viewspace-2095945/
将数据库的表映射为ES索引.索引歌曲ID,歌曲名称和演唱者
创建索引结构
index.json:
{
"mappings":{
"sod_song_ksc":{
"properties":{
"songid":{"type":"long","store":"yes","index":"not_analyzed"},
"name":{"type":"string","store":"yes","index":"analyzed","analyzer":"ik"},
"singername":{"type":"string","store":"yes","index":"analyzed","analyzer":"ik"}
}
}
}
}
curl -XPOST http://192.168.1.105:9200/songod --data-binary @index.json
批量导入数据
[elasticsearch/tmp]$curl -XPUT http://192.168.1.105:9200/_bulk -d'
> {"create":{"_index":"songod","_type":"sod_song_ksc","_id":90978059}}
> {"songid":90978059,"songname":"思念一个荒废的名字","singername":"陈楚生"}
> {"create":{"_index":"songod","_type":"sod_song_ksc","_id":90978058}}
> {"songid":90978058,"songname":"让爱绽放","singername":"陈慧娴"}
> {"create":{"_index":"songod","_type":"sod_song_ksc","_id":90978057}}
> {"songid":90978057,"songname":"天边有个你","singername":"陈思思"}
> {"create":{"_index":"songod","_type":"sod_song_ksc","_id":90978052}}}
> {"songid":90978052,"songname":"那些让你死去活来的女孩","singername":"陈奕迅"}
> {"create":{"_index":"songod","_type":"sod_song_ksc","_id":90978048}}
> {"songid":90978048,"songname":"石壁我的家园","singername":"阿鲁阿卓"}
> '
查看导入数据
http://192.168.1.105:9200/songod/sod_song_ksc/_search?q=*&pretty
curl -XDELETE http://192.168.1.105:9200/songod/
http://blog.itpub.net/29254281/viewspace-2095945/
将数据库的表映射为ES索引.索引歌曲ID,歌曲名称和演唱者
创建索引结构
index.json:
{
"mappings":{
"sod_song_ksc":{
"properties":{
"songid":{"type":"long","store":"yes","index":"not_analyzed"},
"name":{"type":"string","store":"yes","index":"analyzed","analyzer":"ik"},
"singername":{"type":"string","store":"yes","index":"analyzed","analyzer":"ik"}
}
}
}
}
curl -XPOST http://192.168.1.105:9200/songod --data-binary @index.json
批量导入数据
[elasticsearch/tmp]$curl -XPUT http://192.168.1.105:9200/_bulk -d'
> {"create":{"_index":"songod","_type":"sod_song_ksc","_id":90978059}}
> {"songid":90978059,"songname":"思念一个荒废的名字","singername":"陈楚生"}
> {"create":{"_index":"songod","_type":"sod_song_ksc","_id":90978058}}
> {"songid":90978058,"songname":"让爱绽放","singername":"陈慧娴"}
> {"create":{"_index":"songod","_type":"sod_song_ksc","_id":90978057}}
> {"songid":90978057,"songname":"天边有个你","singername":"陈思思"}
> {"create":{"_index":"songod","_type":"sod_song_ksc","_id":90978052}}}
> {"songid":90978052,"songname":"那些让你死去活来的女孩","singername":"陈奕迅"}
> {"create":{"_index":"songod","_type":"sod_song_ksc","_id":90978048}}
> {"songid":90978048,"songname":"石壁我的家园","singername":"阿鲁阿卓"}
> '
查看导入数据
http://192.168.1.105:9200/songod/sod_song_ksc/_search?q=*&pretty
{ "took" : 4, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 5, "max_score" : 1.0, "hits" : [ { "_index" : "songod", "_type" : "sod_song_ksc", "_id" : "90978057", "_score" : 1.0, "_source" : { "songid" : 90978057, "songname" : "天边有个你", "singername" : "陈思思" } }, { "_index" : "songod", "_type" : "sod_song_ksc", "_id" : "90978059", "_score" : 1.0, "_source" : { "songid" : 90978059, "songname" : "思念一个荒废的名字", "singername" : "陈楚生" } }, { "_index" : "songod", "_type" : "sod_song_ksc", "_id" : "90978058", "_score" : 1.0, "_source" : { "songid" : 90978058, "songname" : "让爱绽放", "singername" : "陈慧娴" } }, { "_index" : "songod", "_type" : "sod_song_ksc", "_id" : "90978048", "_score" : 1.0, "_source" : { "songid" : 90978048, "songname" : "石壁我的家园", "singername" : "阿鲁阿卓" } }, { "_index" : "songod", "_type" : "sod_song_ksc", "_id" : "90978052", "_score" : 1.0, "_source" : { "songid" : 90978052, "songname" : "那些让你死去活来的女孩", "singername" : "陈奕迅" } } ] } }删除索引
curl -XDELETE http://192.168.1.105:9200/songod/
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29254281/viewspace-2095990/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29254281/viewspace-2095990/