ElasticSearch创建索引

已经搭建好了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
{
  "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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值