ElasticSearch添加索引


  

1. 編寫索引內容

  節點解釋:

  settings:配置信息

  "number_of_replicas": 0  不需要備份(單節點的ElasticSearch使用)

  "mappings":  映射內容

  "dynamic":false  是否動態索引,這里使用的是false,表示索引的固定的,不需要修改。

  "properties": 屬性結構內容

  "index":"true"  需要分詞處理的結構

  type對應的數據類型,text文本(長字符串),integer數字,date時間,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. 創建索引

  使用Postmen發送創建索引請求

  (1)地址欄后半段是索引名稱

  (2)請求使用的PUT方式,選擇Body,raw形式,采用JSON格式發送

  創建成功的顯示結果:

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

  在ElasticSearch-Head里查看結果:

 

3. 創建索引時的報錯:

  錯誤1:Root mapping definition has unsupported parameters

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

  

  問題2:Could not convert [title.index] to boolean

  原因:也是新版本的問題,之前版本的index屬性寫法是"analyze",現在只能設置true, false, "true","false"

 

 
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM