工作相关和扩展核心能力的需要,采用较为简单的方法来学习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
二、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来写的话就是
四、可能出错的问题
1、由于代码版本的错误,需要将https改成http
2、elasticsearch.ApiError: ApiError(406报错……
需要把elasticsearch安装版本和python Elasticsearch第三方库(模块)版本保持一致就可以解决。
重要参考资料:
Elastic 中国社区官方博客_Elastic,Elasticsearch,Kibana
标签:9200,第一天,简明,json,elasticsearch,Elasticsearch,Type,localhost From: https://blog.51cto.com/jsxyhelu2017/8985916