2016-06-06 19 views
0

我正在從betfair api-ng獲取marketcatalogue數據,我想將它存儲到elasticsearch(v1.4.4)中。爲來自遠程api的字典定義elasticsearch映射

來自API的數據包含很多屬性和複雜類型。有一個名爲的跑步者其中包含相關數據和Dictionary<string,string>。我想定義這樣的映射,所以它將數據存儲在Elasticsearch中。樣本映射下面是:

"marketcatalogue" :{ 
    "properties":{ 
     "marketId":{"type":"string", "index": "not_analyzed" }, 
     "marketName":{"type":"string", "analyzer":"keylower" }, 
     "isMarketDataDelayed":{"type","boolean"}, 
     "description":{ 
      "persistenceEnabled":{"type","boolean"}, 
      "bspMarket":{"type","boolean"}, 
      "marketTime":{"type" : "date","format":"dateOptionalTime"}, 
      "suspendTime":{"type" : "date","format":"dateOptionalTime"}, 
      "settleTime":{"type" : "date","format":"dateOptionalTime"}, 
      "bettingType":{"type":"integer"}, 
      "turnInPlayEnabled":{"type","boolean"}, 
      "marketType":{"type":"string", "analyzer":"keylower" }, 
      "regulator":{"type":"string", "analyzer":"keylower" }, 
      "marketBaseRate":{"type":"double"}, 
      "discountAllowed":{"type","boolean"}, 
      "wallet":{"type":"string", "analyzer":"keylower"}, 
      "rules":{"type":"string"}, 
      "rulesHasDate":{"type","boolean"}, 
      "clarifications":{"type":"string"} 
     }, 
     "runners":{ 
      "selectionId":{"type":"long"}, 
      "runnerName":{"type":"string", "analyzer":"keylower"}, 
      "handicap":{"type":"double"}, 
      "metadata":{ 

      } 
     } 
    } 
} 

}

medatadataDictionary<string,string>從API來和它可以包含像數據:

<"TRAINER_NAME", "John">, <"WEARING", "Wearing one">,.... 

將數據存儲到類型是不是一個大問題,但問題是如何定義字典的映射。

任何幫助將節省我很多時間,並會讓我學習映射創作更好的方法。

在此先感謝。

回答

2

Elasticsearch中的每個字段都可以是一個奇異值或一組值。這包括對象:

"metadata" : { 
    "type" : "object", 
    "properties" : { 
    "key" : { "type" : "string", "index" : "not_analyzed" }, 
    "value" : { "type" : "string", "index" : "not_analyzed" } 
    } 
} 

然後,如果你的JSON看起來是這樣,這將是上述映射回升:

{ 
    ..., 
    "metadata": [ 
    { "key" : "TRAINER_HOME", "value" : "John" }, 
    { "key" : "WEARING", "value" : "Wearing one" } 
    ] 
} 

或者,如果你甚至不希望搜索的數據,但是您希望將它作爲_source的一部分接受到索引中,但實際上並不索引各個字段(如果您實際上不打算使用元數據進行搜索,則會減小索引的大小):

{ 
    "metadata" : { 
    "type" : "object", 
    "dynamic" : false 
    } 
} 

這意味着你不能對ES內部的數據做任何事情,但當你對其他字段進行查詢時,它會在那裏。

如果你真正想要搜索的元數據,那麼你可能使用"type" : "nested" rather than object(一定要採取注意到在底部嚴重,沒有什麼是免費的)。

+0

你的建議奏效。非常感謝 –