Elasticsearch Postman簡單入門(創建索引並新增)


當然ES的安裝我就不詳細的寫了,百度一大堆,本人現在用的是6.2.3 的版本。

1.安裝ES后我們開始創建索引和mapping;

 

--PUT http://localhost:9200/local_mst_student_idx_1   

 local_mst_student_idx_1:代表索引名。

mappings:

{
    "mappings":{
        "mst_student":{
            "properties":{
                "id":{
                    "type":"long",
                    "fields":{
                        "keyword":{
                            "type":"keyword",
                            "ignore_above":256
                        }
                    }
                },
                "stu_code":{
                    "type":"text",
                    "fields":{
                        "keyword":{
                            "type":"keyword",
                            "ignore_above":256
                        }
                    }
                },
                "stu_name":{
                    "type":"text",
                    "fields":{
                        "keyword":{
                            "type":"keyword",
                            "ignore_above":256
                        }
                    }
                },
                "stu_age":{
                    "type":"integer",
                    "fields":{
                        "keyword":{
                            "type":"keyword",
                            "ignore_above":256
                        }
                    }
                },
                "stu_date":{
                    "type":"long",
                    "fields":{
                        "keyword":{
                            "type":"keyword",
                            "ignore_above":256
                        }
                    }
                },
                "stu_bool":{
                    "type":"boolean",
                    "fields":{
                        "keyword":{
                            "type":"keyword",
                            "ignore_above":256
                        }
                    }
                }
            }
        }
    }
}

mapping創建后我們可以查看一下mapping是否已經在ES中存在:

--Get  http://localhost:9200/local_mst_student_idx_2/_mapping?pretty

 

確認完后我們就開始新增操作了;

--Post http://127.0.0.1:9200/local_mst_student_idx_2/mst_student/1

body參數:

{
    "id":"1",
    "stu_code":"1A0001",
    "stu_name":"張三 ",
    "stu_age":"18",
    "stu_date":"1528887157717",
    "stu_bool":"true"
}

新增完成后我們怎么查看到剛才我們新增的數據呢?下面我就寫一個根據id查詢的請求。

--Post  http://localhost:9200/local_mst_student_idx_2/_search?pretty

bosy參數:

{
    "query":{
        "match":{
            "id":"1"
        }
    }
}

 

我就簡單給大家講解一下上面返回的參數;其實我們只關注一下hits內部的參數值就行了。

took:是查詢花費的時間,毫秒單位。

time_out:標識查詢是否超時。

_shards:描述了查詢分片的信息,查詢了多少個分片、成功的分片數量、失敗的分片數量等。

hits:搜索的結果,total是全部的滿足的文檔數目,hits是返回的實際數目(默認是10)。

_score是文檔的分數信息,與排名相關度有關,參考各大搜索引擎的搜索結果,就容易理解。

total:1;(代表當前ES里總數只有一條數據,不管你發送任何請求,ES都會把總數返回)

_index:我們指定查詢的索引(類似數據庫的某個庫)。

_type:我們指定查詢的文檔(類似數據庫的某張表)

_id:查詢指定的id。

_source:查詢返回數據。

 

看完麻煩給個贊吧,我會繼續努力的~

 


免責聲明!

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



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