2017-01-19 34 views
0

我是一個iOS Swift開發商和我使用ElasticSearch我的應用程序中。我試圖圍繞如何申報typeEStypedocument之間的區別是什麼,它與object/data model最相似。如何創建ElasticSearch型

Swift我會創造一個objectdata model這樣的:

class Sneakers{ 
     var condition: String? 
     var name: String? 
} 

的是說我創建了一個名爲運動鞋的對象,具有2個屬性:「條件」和「名」兩String類型。

我知道創建和設置我的ES到Index我使用以下命令:

curl -XPOST <bonsai_url>/myIndexName //I'm using Heroku & Bonsai for my ES cluster 

我可以再設置一個類型,像這樣

curl -XPOST <bonsai_url>/myIndexName/sneakerType 

我在哪裏是怎麼輸做我設置sneakerType用我的運動鞋的數據模型作爲參考來搜索呢?在我的應用程序用戶可以搜索基於運動鞋對象的鞋類。

我知道這是沿

curl -XPOST <bonsai_url>/myIndexName/sneakerType -d ' 
{ 
    "sneakers": { 
     "properties": { 
     "condition": { 
      "type": string 
     }, 
     "name": { 
      "type": string 
     } 
     } 
    } 
} 
' 

線的東西我的問題是在ES:

  1. 什麼是type和類型和文檔之間的document
  2. 之間的區別這將是一個 數據模型的等效,將fieldsproperties等效?
  3. 後創建我index名和type,如何讓我的type到 參考我data model,它的properties
  4. 我的最後一個問題是什麼是_mapping的,我應該用在我的curl命令呢?
+0

https://www.elastic.co/指南/ EN/elasticsearch /引導/電流/ mapping.html – blackmamba

回答

1

ES a type相當於class/data model/object

ESfields相當於類/數據模型/對象的properties

一個document是實際上是被搜索的索引裏面是什麼。如果我映射的sneakersindextype有2對球鞋objects的那麼index將有2 documents它裏面。

Mappings是如何設置的index使得type和它的properties將等同於我的objectdata model,它的properties

我首先創建了一個名爲sneakerfile.json 文件,並添加代碼裏它

{ 
    "sneakers": { 
     "properties": { 
     "condition": { 
      "type": "string" 
     }, 
     "name": { 
      "type": "string" 
     } 
     } 
    } 
} 
//sneakers is being treated like my Sneakers Swift class type 
//the properties condition & name are of type string just like my Swift's Sneaker's class's properties 

然後在終端我通過運行

curl -XPOST <BONSAI_URL>/firebase 

創建了ES index現在,我有一個index命名firebase我創建了我的ES type並將其命名爲sneakers,我使用sneaker.json文件填充_mappings關鍵

curl -XPOST <BONSAI_URL>/firebase/_mappings/sneakers [email protected] 

現在,我想看看有什麼我mappings鍵裏面,當我運行:

curl -XGET <BONSAI_URL>/firebase/_mappings?pretty 

我會得到

{ 
    "firebase" : { 
    "mappings" : { 
     "sneakers" : { 
     "properties" : { 
      "condition" : { 
      "type" : "string" 
      }, 
      "name" : { 
      "type" : "string" 
      } 
     } 
     } 
    } 
    } 
} 
相關問題