elastic search&logstash&kibana 学习历程(二)es基础知识

简介:esindex索引,document文档对象,副本,多节点集群等基础知识

1、通俗的解释:

Elasticsearch中,文档归属于一种类型(type),而这些类型存在于索引(index), 索引名称必须是小写

Relational DB -> Database -> Table -> Row -> Column

Elasticsearch -> Indice   -> Type  -> Document -> Field

2、分片shards

数据量特大,没有足够大的硬盘空间来一次性存储,且一次性搜索那么多的数据,响应跟不上es提供把数据进行分片存储,这样方便进行拓展和提高吞吐(分布式)

3、副本replicas

 

分片的拷贝,当主分片不可用的时候,副本就充当主分片进行使用(高可用)

4Elasticsearch中的每个索引分配5个主分片和1个副本

如果你的集群中至少有两个节点,你的索引将会有5个主分片和另外5个复制分片(1个完全拷贝),这样每个索引总共就有10个分片。

 

search搜索语句入门之URL搜索

简介:讲解URL中的_search搜索语句的基本使用,美化响应结果, 索引的基础操作

http://localhost:9200/_cat/health?v   #查看集群的状态
http://localhost:9200/_cluster/health?v  #查看集群的状态
http://localhost:9200/_cat/nodes?v  #查看节点列表
http://localhost:9200/_cat/indices?v  #查看所有索引
curl -XPUT http://localhost:9200/test  #新增test索引
curl -XDELETE http://localhost:9200/test  #删除test索引 ?perrty
curl -XPUT -H "Content-Type: application/json" 'localhost:9200/test/test/2?pretty' -d '
{"title": "我们的一家",
"content":"我喜欢一回家就有暖洋洋的灯光在等待, 我喜欢一起床就看到大家微笑的脸庞, 我喜欢一出门就为了家人和自己的理想打拼, 我喜欢一家人心朝着同一个方向眺望. 哦! 我喜欢快乐时马上就要和你分享,
"
}
' #插入一条数据

curl -XGET 'localhost:9200/test/test/2        #id查询记录

curl -XGET 'http://localhost:9201/test/test/_search?q=title:一家'      #   根据title进行搜索

 

 elsaticsearch 查询范例(命令行的方式)

curl -XPOST -H "Content-Type: application/json" 'http://192.168.1.127:9200/test/test/_search' -d '{"query":{"term":{ "title" : "elk" }}}'       #查询标题中带有elk字样的,在使用curl命令时注意空格问题会报500和400的错误

curl -XPOST -H "Content-Type: application/json" 'http://192.168.1.127:9200/test/test/_search' -d '{
    "query":{
        "bool":{
            "filter":{
                "range":{
                    "PV":{"gt":15}
                }
            }
        
        }
    }
}'     #命令不能直接使用要把空格去掉,查询表中PV大于15的数据

curl -XPOST -H "Content-Type: application/json" 'http://192.168.1.127:9200/test/test/_search' -d '{
    "query":{
        "bool":{
            "filter":{
                "range":{
                    "PV":{"gt":15}
                }
            },
            "must":{
                "match":{
                    "title":"ELK"
                }
            }
        }
    }
}'         #查询PV大于15,title中必须包括elk的数据

 

原文地址:https://www.cnblogs.com/both/p/9068417.html