ElasticSearch建立索引

壹頁書發表於2016-05-08
已經搭建好了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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章