全文檢索 - 4、檢索接口開發(SpringBoot)

上一章 全文檢索 - 3、ElasticSearch使用

一、 添加測試數據

1、創建索引和映射結構

curl -XPUT 'http://192.168.3.27:8201/test_index?pretty' \
   -H "Content-Type: application/json" \
   -d '{"settings":{"number_of_shards":2,"number_of_replicas":1},"mappings":{"properties":{"text":{"type":"text","analyzer":"ik_smart"},"type":{"type": "keyword"},"publish_date": {"type": "date"}}}}'

mapping中字段類型:
1、基本類型text,keyword,date,long,double,boolean,ip,text和keyword都可以保存字符串,text會被解析,keyword適合要進行過濾、排序、聚合的字段,搜索時要使用精確查詢;
2、Json的層級類型,可以保存多層級Json內容;
3、複雜的類型,geo_point地理位置信息等。

2、添加測試數據
添加四條測試數據(數據這裏審覈不通過)
新聞地址:https://baijiahao.baidu.com/s?id=1669616707242562645&wfr=spider&for=pc,取其中內容放入text中

curl -XPUT 'http://192.168.3.27:8201/test_index/_doc/1?pretty' \
    -H "Content-Type: application/json" \
    -d '{"text":"","typ
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章