【问题标题】:Elastic Search existing field mappingElastic Search 现有字段映射
【发布时间】:2014-08-03 06:48:31
【问题描述】:

我是弹性搜索的新手,我创建了一个类型为“提及”的索引“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"
        }

此外,我们如何为每个“TYPE”创建唯一的映射,而不仅仅是索引。

谢谢

【问题讨论】:

  • 您能否提供您正在索引的文档?您还可以为每种类型创建一个映射。你不能真正为每个索引创建一个映射。
  • @JettroCoenradie 提供了一个示例文档,它基本上是一条推文。

标签: elasticsearch


【解决方案1】:

这样做,

把映射写成,

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-15
    • 2021-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多