首先創建索引 , 並建立字段mapping, 字段hobby使用的是ik_smart分詞器
記住要用put請求 , 然後index和type 需要和類的註解上面一致 , 否則springDataSearch 查詢不出來, 數據body如下:
{
"settings": {
"index": {
"number_of_shards": "1",
"number_of_replicas": "0"
}
},
"mappings": {
"person": {
"properties": {
"age": {
"type": "integer"
},
"mail": {
"type": "keyword"
},
"hobby": {
"type": "text",
"analyzer": "ik_smart"
}
}
}
}
}
然後插入兩條數據:
{
"age": 20,
"mail": "[email protected]",
"hobby": "進口紅酒真好喝"
}
{
"age": 20,
"mail": "[email protected]",
"hobby": "我喜歡紅色口紅"
}