Springboot+Elasticsearch+IK分詞器實現全文檢索(1)
下載Elasticsearch
大神的國內下載地址,國外網站的下載地址速度很慢建議使用國內的
[https://blog.csdn.net/weixin_37281289/article/details/101483434](https://blog.csdn.net/weixin_37281289/article/details/101483434)
下載完成后進入bin目錄啟動
啟動成功后
在瀏覽器或者postman上輸入[http://localhost:9200/](http://localhost:9200/)
成功會輸出以下數據
```java
{
? "name" : "wkkmUZK",
? "cluster_name" : "elasticsearch",
? "cluster_uuid" : "bRf9t_hvRB6w-wJ7e2xiPA",
? "version" : {
? ? "number" : "6.3.2",
? ? "build_flavor" : "default",
? ? "build_type" : "tar",
? ? "build_hash" : "053779d",
? ? "build_date" : "2018-07-20T05:20:23.451332Z",
? ? "build_snapshot" : false,
? ? "lucene_version" : "7.3.1",
? ? "minimum_wire_compatibility_version" : "5.6.0",
? ? "minimum_index_compatibility_version" : "5.0.0"
? },
? "tagline" : "You Know, for Search"
}
```
下載kibana可對Elasticsearch進行操作
國內下載地址
[https://blog.csdn.net/weixin_37281289/article/details/101483434](https://blog.csdn.net/weixin_37281289/article/details/101483434)
官網下載地址[https://www.elastic.co/cn/downloads/elasticsearch](https://www.elastic.co/cn/downloads/elasticsearch)
推薦使用國內對速度快
下載后進入bin目錄啟動服務
啟動kibana時要保證已經將Elasticsearch服務啟動,因為kibana是依賴于Elasticsearch
啟動后輸入[http://localhost:5601/](http://localhost:5601/)即可進入頁面進行操作
點擊頁面上以下按鈕即可進入編輯頁面用來編輯Elasticsearch增刪改查語句
刪除某個index
```java
DELETE /blog
```
新增數據
```java
PUT /abc//創建index
//向index中添加數據
POST /abc/10
{
"first_name" : "John",
"last_name":"Smith",
"age":25,
"about":"I love go to rock climbing",
"interests":["sports","music"]
}
```
查詢數據
```java
GET /person/_doc/1根據id
GET /person/_doc/_search?q=age:25根據age
POST /person/_search
{
"query":{
? "bool": {
? ? "should": [
? ? ? {
? ? ? ? "match": {
? ? ? ? ? "last_name": "Smith"
? ? ? ? }
? ? ? }
? ? ]
? }
}
}根據姓名等用post就需要這么寫
第二種多個條件用should時代表的是or的意思
POST /person/_search
{
"query":{
? "bool": {
? ? "should": [
? ? ? {
? ? ? ? "match": {
? ? ? ? ? "last_name": "Smith"
? ? ? }
? ? ? }
? ? ? ,
? ? ? {
? ? ? ? "match": {
? ? ? ? ? "about": "rock"
? ? ? ? }
? ? ? }
? ? ]
? }
}
}
第三種多個條件下用must代表and
POST /person/_search
{
"query":{
? "bool": {
? ? "must": [
? ? ? {
? ? ? ? "match": {
? ? ? ? ? "last_name": "Smith"
? ? ? }
? ? ? }
? ? ? ,
? ? ? {
? ? ? ? "match": {
? ? ? ? ? "about": "rock"
? ? ? ? }
? ? ? }
? ? ]
? }
}
}
```