码迷,mamicode.com
首页 > 其他好文 > 详细

elasticsearch入门及安装

时间:2019-12-14 21:24:22      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:保存   tle   cat   asd   图片   技术   not   img   line   

参考教程

elasticsearch入门教程:https://www.yiibai.com/elasticsearch/elasticsearch-getting-start.html

Java JDK安装和配置:https://www.yiibai.com/java/java_environment_setup.html

 

网上的elasticsearch和jdk安装包下载速度太慢了,这是我下载下来保存的

=======================================================

elasticsearch windows安装包:链接: https://pan.baidu.com/s/1fE6rE-lGuwJuA29_0C_VXw 提取码: 5v2v

Java JDK windows64位安装包:链接: https://pan.baidu.com/s/1NVuARW_cK6WeNy-VhTEiVQ 提取码: 8jxs 

curl  windows安装包:链接: https://pan.baidu.com/s/1RLOQOWEo2vt_8YkK7fI-ZQ 提取码: wpny 

=======================================================

 

Elasticsearch需要先安装JDK并配置环境变量,之后下载安装Elasticsearch

技术图片

 

 

 启动 ElasticSearch

E:\elasticsearch-7.5.0-windows-x86_64\elasticsearch-7.5.0\bin>elasticsearch.bat

启动成功

技术图片

 

 

 启动成功后浏览器地址栏输入:http://localhost:9200/

技术图片

 

 

 创建索引

curl -H "Content-Type: application/json" -XPUT "http://localhost:9200/movies/movie/1" -d "{\"title\": \"The Godfather\",\"director\":\"Francis Ford Coppola\",\"year\": 1972}"
{"_index":"movies","_type":"movie","_id":"1","_version":3,"result":"updated","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":2,"_primary_term":1}

注意,{}内的双引号记得加反斜杠\转义

由ID获取文档/索引

curl  -H "Content-Type: application/json" -XGET "http://localhost:9200/movies/movie/1" -d‘‘
{"_index":"movies","_type":"movie","_id":"1","_version":6,"_seq_no":5,"_primary_term":1,"found":true,"_source":{"title": "The Godfather","director":"Francis Ford Coppola","year": 1972}}

删除文档

curl  -H "Content-Type: application/json" -XGET "http://localhost:9200/movies/movie/1" -d‘‘
{"_index":"movies","_type":"movie","_id":"1","found":false}

搜索所有索引和类型 _search

curl -H "Content-Type: application/json"  -XGET "http://localhost:9200/_search"
{"took":1,"timed_out":false,"_shards":{"total":3,"successful":3,"skipped":0,"failed":0},"hits":{"total":{"value":3,"relation":"eq"},"max_score":1.0,"hits":[{"_index":"movies","_type":"movie","_id":"1","_score":1.0,"_source":{"title": "gangtie","director": "pfeiliu","year": 1999,"genres": ["nishishui", "asdwqe"]}},{"_index":"movies","_type":"movie","_id":"2","_score":1.0,"_source":{"title": "The Godfather","director": "Francis Ford Coppola","year": 1972,"genres": ["Crime", "Drama"]}},{"_index":"movies","_type":"movie","_id":"3","_score":1.0,"_source":{"title": "lawer","director": "lean","year": 1989,"genres": ["youar", "pl"]}}]}}

搜索某索引的数据类型

curl -H "Content-Type: application/json"  -XGET "http://localhost:9200/movies/_search"
{"took":1,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":3,"relation":"eq"},"max_score":1.0,"hits":[{"_index":"movies","_type":"movie","_id":"1","_score":1.0,"_source":{"title": "gangtie","director": "pfeiliu","year": 1999,"genres": ["nishishui", "asdwqe"]}},{"_index":"movies","_type":"movie","_id":"2","_score":1.0,"_source":{"title": "The Godfather","director": "Francis Ford Coppola","year": 1972,"genres": ["Crime", "Drama"]}},{"_index":"movies","_type":"movie","_id":"3","_score":1.0,"_source":{"title": "lawer","director": "lean","year": 1989,"genres": ["youar", "pl"]}}]}}

在指定索引中显式搜索指定类型的文档

curl -H "Content-Type: application/json"  -XGET "http://localhost:9200/movies/movie/_search"
{"took":1,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":3,"relation":"eq"},"max_score":1.0,"hits":[{"_index":"movies","_type":"movie","_id":"1","_score":1.0,"_source":{"title": "gangtie","director": "pfeiliu","year": 1999,"genres": ["nishishui", "asdwqe"]}},{"_index":"movies","_type":"movie","_id":"2","_score":1.0,"_source":{"title": "The Godfather","director": "Francis Ford Coppola","year": 1972,"genres": ["Crime", "Drama"]}},{"_index":"movies","_type":"movie","_id":"3","_score":1.0,"_source":{"title": "lawer","director": "lean","year": 1989,"genres": ["youar", "pl"]}}]}}

 

常见错误处理:

错误:{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}

解决:添加:-H "Content-Type: application/json"

 

错误:{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse"}],"type":"mapper_parsing_exception","reason":"failed to parse","caused_by":{"type":"json_e_o_f_exception","reason":"Unexpected end-of-input in field name\n at [Source: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper@3c1b21d; line: 1, column: 133]"}},"status":400}curl: (3) unmatched close brace/bracket in URL position 5:
1972}

解决:在{}内的双引号都加上一个"\"转义

 

查看集群健康状况:

浏览器输入:http://localhost:9200/_cat

技术图片

 

 或者http://localhost:9200/_cat/health?v

技术图片

 

 查看所有索引:

http://localhost:9200/_cat/indices?v

技术图片

elasticsearch入门及安装

标签:保存   tle   cat   asd   图片   技术   not   img   line   

原文地址:https://www.cnblogs.com/pfeiliu/p/12040597.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!