Fahimtar Index kuma Mapping a ciki Elasticsearch

Tabbas! Ga fassarar bayani da misalai ga Index kuma Mapping a cikin Elasticsearch:

Index in Elasticsearch

In yana kama da ma'ajin bayanai a tsarin sarrafa bayanai na gargajiya(DBMS) Index. Elasticsearch Yana adana tarin takardu masu alaƙa. Kowannensu Index ya yi daidai da takamaiman nau'in bayanai a cikin aikace-aikacen ku. Misali, a cikin aikace-aikacen kasuwancin e-commerce, zaku iya ƙirƙirar Index don adana bayanai game da samfuran, wani Index don adana bayanai game da masu amfani da oda.

Kowanne Index cikin Elasticsearch an raba shi zuwa ƙananan shards don rarraba bayanai. Shard karamin sashi ne na Index, kuma kowane Shard ana iya adana shi akan kulli daban a cikin Elasticsearch tari. Rarraba bayanai cikin shards yana inganta bincike da aikin tambaya kuma yana haɓaka haɓakar tsarin.

Misali, don ƙirƙirar sabon Index mai suna products  a cikin Elasticsearch, zaku iya amfani da API ko kayan aikin gudanarwa kamar Kibana don aiwatar da umarni mai zuwa:

PUT /products  
{  
  "settings": {  
    "number_of_shards": 3,  
    "number_of_replicas": 2  
  }  
}  

A cikin misalin da ke sama, mun ƙirƙiri mai Index products tare da 3 shard da 2 replica kowanne shard don tabbatar da samuwa da madadin bayanai.

 

Mapping in Elasticsearch

Mapping shine tsari na ayyana yadda Elasticsearch ake adanawa da sarrafa bayanai a cikin Index. Lokacin da kuka ƙara sabon daftarin aiki zuwa Index, Elasticsearch yana amfani da shi Mapping don tantance nau'in bayanan kowane filin a cikin takaddar. Wannan yana taimakawa Elasticsearch fahimtar yadda ake sarrafawa da bincika bayanai a fagage daban-daban.

Misali, idan muna da Index products kuma muna son fayyace Mapping ma filayen name(sunan samfur) da price  (farashin samfur) azaman rubutu da nau'ikan ruwa, bi da bi, zamu iya aiwatar da umarni mai zuwa:

PUT /products/_mapping  
{  
  "properties": {  
    "name": {  
      "type": "text"  
    },  
    "price": {  
      "type": "float"  
    }  
  }  
}  

A cikin misalin da ke sama, mun ayyana Mapping ma'anar products  Index, tare da name  filin da ke da nau'in bayanai text da filin farashin yana da nau'in bayanan float. Wannan yana tabbatar da cewa lokacin da Elasticsearch aka karɓi sabbin takardu don products  Fihirisar, zai adana da sarrafa name  filayen da “farashi” bisa ga ƙayyadaddun nau'ikan bayanai.

Index kuma Mapping suna taka muhimmiyar rawa wajen tsarawa da sarrafa bayanai a cikin Elasticsearch. Suna taimakawa Elasticsearch sosai don fahimta da sarrafa bayanai, inganta bincike da ayyukan tambaya, da kuma samar da damar daidaitawa ga tsarin.