Elasticsearch簡明學習(第一天)

工作相關和擴展核心能力的需要,採用較爲簡單的方法來學習Elasticsearch,作相關記錄備查。

一、採用Docker安裝

sudo docker pull elasticsearch:7.7.0
sudo docker images
sudo docker run --name elasticsearch -d -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -e "discovery.type=single-node" -p 9200:9200 -p 9300:9300 elasticsearch:7.7.0

a4e6e652-3d83-4407-a72c-177292a22728

ed8445ca-6ed3-4bb8-937a-1aa46482d1a5

二、Curl進行測試

$ curl -XGET -u "elastic:changeme" 'http://localhost:9200/' -H 'Content-Type: application/json'
curl -XPUT 'http://localhost:9200/twitter/_doc/1?pretty' -H 'Content-Type: application/json' -d '
{
    "user": "kimchy",
    "post_date": "2009-11-15T13:12:00",
    "message": "Trying out Elasticsearch, so far so good?"
}'
curl -XPUT 'http://localhost:9200/twitter/_doc/2?pretty' -H 'Content-Type: application/json' -d '
{
    "user": "kimchy",
    "post_date": "2009-11-15T14:12:12",
    "message": "Another tweet, will it be indexed?"
}'
curl -XPUT 'http://localhost:9200/twitter/_doc/3?pretty' -H 'Content-Type: application/json' -d '
{
    "user": "elastic",
    "post_date": "2010-01-15T01:46:38",
    "message": "Building the site, should be kewl"
}'

三、python編寫代碼

使用python來寫的話就是

fe577cc2-0059-434e-a089-5e5105607703

四、可能出錯的問題

1、由於代碼版本的錯誤,需要將https改成http

60e09548-4dbe-4261-ad49-f910993eb6fb

2、elasticsearch.ApiError: ApiError(406報錯……

需要把elasticsearch安裝版本和python Elasticsearch第三方庫(模塊)版本保持一致就可以解決。

重要參考資料:

Elastic 中國社區官方博客_Elastic,Elasticsearch,Kibana-CSDN博客

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章