弹性搜索现有字段映射

时间:2014-08-03 06:48:31

标签: elasticsearch

我是弹性搜索新手,我创建了一个索引" cmn"提及"提及"。我正在尝试将现有solr中的数据导入到elasticsearch中,因此我想将现有字段映射到_id字段。

我在/ config / mappings / cmn /,

下创建了以下文件
{
    "mappings": {
    "mentions":{
        "_id" : {
            "path" : "docKey"
        }
      }
    }
}

但是这似乎并没有起作用,每次我为记录编制索引时都会创建以下_id,

        "_index": "cmn",
        "_type": "mentions",
        "_id": "k4E0dJr6Re2Z39HAIjYMmg",
        "_score": 1

此外,映射不会反映出来。我也尝试了以下选项,

{
    "mappings": {
        "_id" : {
            "path" : "docKey"
        }
    }
}

示例文档:基本上是一条推文。

 {
           "usrCreatedDate": "2012-01-24 21:34:47",
           "sex": "U",
           "listedCnt": 2,
           "follCnt": 432,
           "state": "Southampton",
           "classified": 0,
           "favCnt": 468,
           "timeZone": "Casablanca",
           "twitterId": 473333038,
           "lang": "en",
           "stnostem": "#ootd #ootw #fashion #styling #photography #white #pink #playsuit #prada #sunny #spring http://t.co/YbPFrXlpuh",
           "sourceId": "tw",
           "timestamp": "2014-04-09T22:58:00.396Z",
           "sentiment": 0,
           "updatedOnGMTDate": "2014-04-09T22:56:57.000Z",
           "userLocation": "Southampton",
           "age": 0,
           "priorityScore": 57.4700012207031,
           "statusCnt": 14612,
           "name": "YazzyK",
           "profilePicUrl": "http://pbs.twimg.com/profile_images/453578494556270594/orsA0pKi_normal.jpeg",
           "mentions": "",
           "sourceStripped": "Instagram",
           "collectionName": "STREAMING",
           "tags": "557/161/193/197",
           "msgid": 1397084280396.33,
           "_version_": 1464949081784713200,
           "url2": "{\"urls\":[{\"url\":\"http://t.co/YbPFrXlpuh\",\"expandedURL\":\"http://instagram.com/p/mliZbgxVZm/\",\"displayURL\":\"instagram.com/p/mliZbgxVZm/\",\"start\":88,\"end\":110}]}",
           "links": "http://t.co/YbPFrXlpuh",
           "retweetedStatus": "",
           "twtScreenName": "YazKader",
           "postId": "454030232501358592",
           "country": "Bermuda",
           "message": "#ootd #ootw #fashion #styling #photography #white #pink #playsuit #prada #sunny #spring http://t.co/YbPFrXlpuh",
           "source": "<a href=\"http://instagram.com\" rel=\"nofollow\">Instagram</a>",
           "parentStatusId": -1,
           "bio": "Live and breathe Fashion. Persian and proud- Instagram: @Yazkader",
           "createdOnGMTDate": "2014-04-09T22:56:57.000Z",
           "searchText": "#ootd #ootw #fashion #styling #photography #white #pink #playsuit #prada #sunny #spring http://t.co/YbPFrXlpuh",
           "isFavorited": "False",
           "frenCnt": 214,
           "docKey": "tw_454030232501358592"
        }

另外,我们如何为每个&#34; TYPE&#34;创建唯一的映射。而不只是索引。

由于

1 个答案:

答案 0 :(得分:0)

这样做,

将映射设为,

PUT index_name/type_name/_mapping
{
   "type_name": {
      "_id": {
         "path": "docKey"
      },
      "properties": {
         "docKey": {
            "type": "string"
         }
      }
   }
}

而且,它会起作用。 (当您索引docKey时,则设置_id)。您不必提供所有映射。