ElasticSearch添加索引代碼實(shí)例解析
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)文章
Spring Bean創(chuàng)建和循環(huán)依賴
這篇文章主要介紹了Spring Bean創(chuàng)建和循環(huán)依賴,講述了Spring容器中?Bean?的創(chuàng)建過(guò)程已經(jīng)主要的方法,另外也著重分析了循環(huán)依賴的問(wèn)題,需要的小伙伴可以參考一下2022-05-05SpringBoot特點(diǎn)之依賴管理和自動(dòng)裝配(實(shí)例代碼)
在使用SpringBoot的時(shí)候,會(huì)自動(dòng)將Bean裝配到IoC容器中,操作也很簡(jiǎn)單,今天小編給大家介紹下SpringBoot特點(diǎn)之依賴管理和自動(dòng)裝配的知識(shí),感興趣的朋友一起看看吧2022-03-03IntelliJ IDEA配置java環(huán)境及解決IDEA不能直接運(yùn)行單個(gè)JAVA文件的問(wèn)題
這篇文章主要介紹了IntelliJ IDEA配置java環(huán)境及解決IDEA不能直接運(yùn)行單個(gè)JAVA文件的問(wèn)題,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-07-07Spring事件監(jiān)聽(tīng)機(jī)制使用和原理解析
Spring的監(jiān)聽(tīng)機(jī)制基于觀察者模式,就是就是我們所說(shuō)的發(fā)布訂閱模式,這種模式可以在一定程度上實(shí)現(xiàn)代碼的解耦,本文將從原理上解析Spring事件監(jiān)聽(tīng)機(jī)制,需要的朋友可以參考下2023-06-06springboot中rabbitmq實(shí)現(xiàn)消息可靠性機(jī)制詳解
這篇文章主要介紹了springboot中rabbitmq實(shí)現(xiàn)消息可靠性機(jī)制詳解,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2021-09-09java并發(fā)學(xué)習(xí)-CountDownLatch實(shí)現(xiàn)原理全面講解
這篇文章主要介紹了java并發(fā)學(xué)習(xí)-CountDownLatch實(shí)現(xiàn)原理全面講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2021-02-02Spring聲明式事務(wù)@Transactional注解實(shí)現(xiàn)元數(shù)據(jù)驅(qū)動(dòng)的事務(wù)管理
這篇文章主要為大家介紹了Spring聲明式事務(wù)@Transactional注解實(shí)現(xiàn)元數(shù)據(jù)驅(qū)動(dòng)的事務(wù)管理示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10Object.wait()與Object.notify()的用法詳細(xì)解析
以下是對(duì)java中Object.wait()與Object.notify()的用法進(jìn)行了詳細(xì)的分析介紹,需要的朋友可以過(guò)來(lái)參考下2013-09-09Springboot整合Redis最簡(jiǎn)單例子分享
這篇文章主要介紹了Springboot整合Redis最簡(jiǎn)單例子分享,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-10-10