简述ES(ElasticSearch入门简介)

2021年12月15日 283点热度 0条评论

简述ES(ElasticSearch入门简介)

根据ES的官方文档,可以简单定义以下3点:

1 .一个分布式的实施文档存储,每个字段可以被索引与搜索

2 .一个分布式实时分析搜索引擎

3 .可以胜任上百个服务节点的扩展,并支持PB级别的结构化或者非结构化数据。

 

Elasticsearch请求和HTTP请求类似,由以下几个相同的部件构成

curl -X'://:/?'-d ''

VERB

适当的 HTTP 方法 或 谓词 : GET`、 `POST`、 `PUT`、 `HEAD 或者 `DELETE`。

PROTOCOL

http 或者 https`(如果你在 Elasticsearch 前面有一个 `https 代理)

HOST

Elasticsearch 集群中任意节点的主机名,或者用 localhost 代表本地机器上的节点。

PORT

运行 Elasticsearch HTTP 服务的端口号,默认是 9200 。

PATH

API 的终端路径(例如 _count 将返回集群中文档数量)。Path 可能包含多个组件,例如:_cluster/stats 和 _nodes/stats/jvm 。

QUERY_STRING

任意可选的查询字符串参数 (例如 ?pretty 将格式化地输出 JSON 返回值,使其更容易阅读)

BODY

一个 JSON 格式的请求体 (如果请求需要的话)

以下内容转载于:https://blog.csdn.net/laoyang360/article/details/51931981

ES Restful API GET、POST、PUT、DELETE、HEAD含义: 
1)GET:获取请求对象的当前状态。 
2)POST:改变对象的当前状态。 
3)PUT:创建一个对象。 
4)DELETE:销毁对象。 
5)HEAD:请求获取对象的基础信息。

Mysql与Elasticsearch核心概念对比示意图 
%title插图%num

 

以上表为依据, 
ES中的新建文档(在Index/type下)相当于Mysql中(在某Database的Table)下插入一行数据。

1、新建文档(类似mysql insert插入操作)

http://localhost:9200/blog/ariticle/1 put
{
"title":"New version of Elasticsearch released!",
"content":"Version 1.0 released today!",
"tags":["announce","elasticsearch","release"]
}

创建成功如下显示:

{

- "_index": "blog",
- "_type": "ariticle",
- "_id": "1 -d",
- "_version": 1,
- "_shards": {
    - "total": 2,
    - "successful": 1,
    - "failed": 0
- },
- "created": true

}

 

%title插图%num

2、检索文档(类似mysql search 搜索select*操作)

http://localhost:9200/blog/ariticle/1/ GET

检索结果如下:

{

- "_index": "blog",
- "_type": "ariticle",
- "_id": "1",
- "_version": 1,
- "found": true,
- "_source": {
    - "title": "New version of Elasticsearch released!",
    - "content": "Version 1.0 released today!",
    - "tags": [
        - "announce"
        - ,
        - "elasticsearch"
        - ,
        - "release"
    - ]
- }

}

如果未找到会提示:

{

- "_index": "blog",
- "_type": "ariticle",
- "_id": "11",
- "found": false

}

查询全部文档如下: 
%title插图%num 
具体某个细节内容检索, 
查询举例1:查询cotent列包含版本为1.0的信息。 
http://localhost:9200/blog/ 
_search?pretty&q=content:1.0

{

- "took": 2,
- "timed_out": false,
- "_shards": {
    - "total": 5,
    - "successful": 5,
    - "failed": 0
- },
- "hits": {
    - "total": 1,
    - "max_score": 0.8784157,
    - "hits": [
        - {
            - "_index": "blog",
            - "_type": "ariticle",
            - "_id": "6",
            - "_score": 0.8784157,
            - "_source": {
                - "title": "deep Elasticsearch!",
                - "content": "Version 1.0!",
                - "tags": [
                    - "deep"
                    - ,
                    - "elasticsearch"
                - ]
            - }
        - }
    - ]
- }

}

查询举例2:查询书名title中包含“enhance”字段的数据信息: 
[root@5b9dbaaa1a ~]# curl -XGET 10.200.1.121:9200/blog/ariticle/_search?pretty -d ‘

> { "query" : {
> "term" :
> {"title" : "enhance" }
> }
> }'
{
  "took" : 189,
  "timed_out" : false,
  "_shards" : {
  "total" : 5,
  "successful" : 5,
  "failed" : 0
  },
  "hits" : {
  "total" : 2,
  "max_score" : 0.8784157,
  "hits" : [ {
  "_index" : "blog",
  "_type" : "ariticle",
  "_id" : "4",
  "_score" : 0.8784157,
  "_source" : {
  "title" : "enhance Elasticsearch!",
  "content" : "Version 4.0!",
  "tags" : [ "enhance", "elasticsearch" ]
  }
  }, {
  "_index" : "blog",
  "_type" : "ariticle",
  "_id" : "5",
  "_score" : 0.15342641,
  "_source" : {
  "title" : "enhance Elasticsearch for university!",
  "content" : "Version 5.0!",
  "tags" : [ "enhance", "elasticsearch" ]
  }
  } ]
  }
}

查询举例3:查询ID值为3,5,7的数据信息: 
[root@5b9dbaaa148a ~]# curl -XGET 10.200.1.121:9200/blog/ariticle/_search?pretty -d ‘

{ "query" : {
"terms" :
{"_id" : [ "3", "5", "7" ] }
}
}'
{
  "took" : 5,
  "timed_out" : false,
  "_shards" : {
  "total" : 5,
  "successful" : 5,
  "failed" : 0
  },
  "hits" : {
  "total" : 3,
  "max_score" : 0.19245009,
  "hits" : [ {
  "_index" : "blog",
  "_type" : "ariticle",
  "_id" : "5",
  "_score" : 0.19245009,
  "_source" : {
  "title" : "enhance Elasticsearch for university!",
  "content" : "Version 5.0!",
  "tags" : [ "enhance", "elasticsearch" ]
  }
  }, {
  "_index" : "blog",
  "_type" : "ariticle",
  "_id" : "7",
  "_score" : 0.19245009,
  "_source" : {
  "title" : "deep Elasticsearch for university!",
  "content" : "Version 2.0!",
  "tags" : [ "deep", "elasticsearch", "university" ]
  }
  }, {
  "_index" : "blog",
  "_type" : "ariticle",
  "_id" : "3",
  "_score" : 0.19245009,
  "_source" : {
  "title" : "init Elasticsearch for university!",
  "content" : "Version 3.0!",
  "tags" : [ "initialize", "elasticsearch" ]
  }
  } ]
  }
}

3、更新文档(类似mysql update操作)

http://localhost:9200/blog/ariticle/1/_update/ POST 
{“script”:”ctx._source.content = ”new version 2.0 20160714”“}

更新后结果显示: 
{

  • “_index”: “blog”,
  • “_type”: “ariticle”,
  • “_id”: “1”,
  • “_version”: 2,
  • “_shards”: { 
    • ”total”: 2,
    • “successful”: 1,
    • “failed”: 0
  • }

}

查询&验证更新后结果:(对比可知,版本号已经更新完毕) 
http://localhost:9200/blog/ariticle/1/

{

- "_index": "blog",
- "_type": "ariticle",
- "_id": "1",
- "_version": 2,
- "found": true,
- "_source": {
    - "title": "New version of Elasticsearch released!",
    - "content": "new version 2.0 20160714",
    - "tags": [
        - "announce"
        - ,
        - "elasticsearch"
        - ,
        - "release"
    - ]
- }

}
`![这里写图片描述](https://img-blog.csdn.net/20160717132407353)``

注意更新文档需要在elasticsearch_winconfigelasticsearch.yml下新增以下内容:

script.groovy.sandbox.enabled: true 
script.engine.groovy.inline.search: on 
script.engine.groovy.inline.update: on 
script.inline: on 
script.indexed: on 
script.engine.groovy.inline.aggs: on 
index.mapper.dynamic: true

4、删除文档(类似mysql delete操作)

http://localhost:9200/blog/ariticle/8/回结果

{

- "found": true,
- "_index": "blog",
- "_type": "ariticle",
- "_id": "8",
- "_version": 2,
- "_shards": {
    - "total": 2,
    - "successful": 1,
    - "failed": 0
- }

}

%title插图%num

5、Kibana可视化分析

5.1、在索引blog上查询包含”university”字段的信息。

%title插图%num

5.2、Kibana多维度分析

%title插图%num

——————————————————————————————————

文章来源于互联网:简述ES(ElasticSearch入门简介)

harry

这个人很懒,什么都没留下

文章评论