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博客

posted on 2023-12-20 20:56  jsxyhelu  阅读(10)  评论(0编辑  收藏  举报

导航