欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ElasticSearch添加索引代碼實(shí)例解析

 更新時(shí)間:2020年04月03日 09:33:25   作者:閑人鶴  
這篇文章主要介紹了ElasticSearch添加索引代碼實(shí)例解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

1. 編寫(xiě)索引內(nèi)容

  節(jié)點(diǎn)解釋?zhuān)?/p>

  settings:配置信息

  "number_of_replicas": 0 不需要備份(單節(jié)點(diǎn)的ElasticSearch使用)

  "mappings": 映射內(nèi)容

  "dynamic":false 是否動(dòng)態(tài)索引,這里使用的是false,表示索引的固定的,不需要修改。

  "properties": 屬性結(jié)構(gòu)內(nèi)容

  "index":"true" 需要分詞處理的結(jié)構(gòu)

  type對(duì)應(yīng)的數(shù)據(jù)類(lèi)型,text文本(長(zhǎng)字符串),integer數(shù)字,date時(shí)間,keyword單詞

elasticsearch 6.X版本的索引文件

{
 "settings":{
  "number_of_replicas": 0
 },
 "mappings":{
  "house":{
   "dynamic":false,
   "properties":{
    "houseId":{"type":"long"},
    "title":{"type":"text", "index":"true"},
    "price":{"type":"integer"},
    "area":{"type":"integer"},
    "createTime":{"type":"date","format":"strict_date_optional_time||epoch_millis"},
    "lastUpdateTime":{"type":"date", "format":"strict_date_optional_time||epoch_millis"},
    "cityEnName":{"type":"keyword"},
    "regionEnName":{"type":"keyword"},
    "direction":{"type":"integer"},
    "distanceToSubway":{"type":"integer"},
    "subwayLineName":{"type":"keyword"},
    "subwayStationName":{"type":"keyword"},
    "tags":{"type":"text"},
    "district":{"type":"keyword"},
    "description":{"type":"text", "index":"true"},
    "layoutDesc":{"type":"text", "index":"true"},
    "traffic":{"type":"text", "index":"true"},
  "roundService": {"type": "text", "index": "true"},
    "rentWay":{"type":"integer"}
   }
  }
 }
}

elasticsearch 7.X版本的索引文件

{
 "settings":{
  "number_of_replicas": 0
 },
 "mappings":{
  "dynamic":false,
  "properties":{
   "title":{"type":"text", "index":"true"},
   "price":{"type":"integer"},
   "area":{"type":"integer"},
   "createTime":{"type":"date","format":"strict_date_optional_time||epoch_millis"},
   "lastUpdateTime":{"type":"date", "format":"strict_date_optional_time||epoch_millis"},
   "cityEnName":{"type":"keyword"},
   "regionEnName":{"type":"keyword"},
   "direction":{"type":"integer"},
   "distanceToSubway":{"type":"integer"},
   "subwayLineName":{"type":"keyword"},
   "subwayStationName":{"type":"keyword"},
   "tags":{"type":"text"},
   "district":{"type":"keyword"},
   "description":{"type":"text", "index":"true"},
   "layoutDesc":{"type":"text", "index":"true"},
   "traffic":{"type":"text", "index":"true"},
  "roundService": {"type": "text", "index": "true"},
   "rentWay":{"type":"integer"}
  }
 }
}

2. 創(chuàng)建索引

  使用Postmen發(fā)送創(chuàng)建索引請(qǐng)求

 ?。?)地址欄后半段是索引名稱

 ?。?)請(qǐng)求使用的PUT方式,選擇Body,raw形式,采用JSON格式發(fā)送

  創(chuàng)建成功的顯示結(jié)果:

{
  "acknowledged": true,
  "shards_acknowledged": true,
  "index": "house"
}

  在ElasticSearch-Head里查看結(jié)果:

3. 創(chuàng)建索引時(shí)的報(bào)錯(cuò):

  錯(cuò)誤1:Root mapping definition has unsupported parameters

  原因:ElasticSearch7.X之后的版本默認(rèn)不在支持指定索引類(lèi)型,默認(rèn)索引類(lèi)型是_doc(隱含:include_type_name=false),所以在mappings節(jié)點(diǎn)后面,直接跟properties就可以了。

  問(wèn)題2:Could not convert [title.index] to boolean

  原因:也是新版本的問(wèn)題,之前版本的index屬性寫(xiě)法是"analyze",現(xiàn)在只能設(shè)置true, false, "true","false"

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論