0.ElasticSearch中核心概念介绍

一、命令行操作(作简单了解就行,一般用JAVA API调用)

对应关系:

RSDB  ES

数据库(db)    索引库(index)

表(table)      类型(type)

行(row)      文档(doc)

字段(filed)     字段(field)

1.创建索引

  执行此操作,创建了caolihua索引库,同时也创建了emp类型,同时也创建了一个id为2的文档。PUT/POST都可以

curl -XPUT http://localhost:9200/caolihua/emp/2 -d'{
"first_name" : "John",
"last_name" : "Smith",
"age" : 25,
"about" : "I love to go rock climbing",
"interests": [ "sports", "music" ]
}'

2.更新

//id 2已存在,所以是更新doc的内容
curl -XPUT http://localhost:9200/bjsxt/emp/2/ -d' {"name":" laoxiao","age":25}'

//局部的更新,如果没有字段则添加字段,有了该字段则更新字段内容
curl -XPOST http://localhost:9200/bjsxt/emp/2/_update -d'{"doc":{"city":"beijing","car":"BMW"}}'

//带_create 会提示是否成功,有了的话则提示失败
curl -XPUT http://localhost:9200/bjsxt/emp/2/_create -d'{"name":" laoxiao","age":25}'
 

 

3.查询索引

二、查询索引:
//根据文档的id查
curl -XGET http://localhost:9200/caolihua/employee/1?pretty      ##pretty是为了以好看的方式显示
curl -i 'http://192.168.1.170:9200/caolihua/emp/1?pretty'        ##  -i显示头文件

//部分选择查询的字段
curl -XGET http://localhost:9200/caolihua/employee/1?_source=about,age    

//查询bjsxt2这个库,employee这个类型,里所有的
curl -XGET http://localhost:9200/caolihua2/employee/_search

//只查这个文档的source
 curl –XGET http://localhost:9200/caolihua/employee/1/_source

//查这个库里所有的
curl -XGET http://localhost:9200/caolihua2/_search


//条件查询  查询这个库里所有类型里面,age=25的文档
curl -XGET http://localhost:9200/caolihua/_search?q=age:25

  //MGET 多个查询
  curl -XGET http://localhost:9200/_mget?pretty -d '{"docs":[{"_index":"caolihua","_type":"emp","_id":2,"_source":"name"} ,{"_index":"caolihua2","_type":"employee","_id":1}]}'



4.删除

curl -XDELETE http://localhost:9200/caolihua/emp/2/

 

二、重要的一些概念

1.集群(cluster)

所有节点属于一个集群,在一个网段默认自动组建

2.分片(shards)

类似于一张藏宝图被切割了很多份,比如5份,这也是默认的index.number_of_shards: 5   分片数

##创建索引库时指定分片数,索引一旦创建完毕,分片数将无法更改

curl -XPUT 'localhost:9200/test/' -d'{"settings":{"number_of_shards":3}} 

3.副本(replicas)

默认副本数是1,每个分片都有副本。

##已有索引的更改副本数方法

curl -XPUT 'localhost:9200/clh/_settings' -d'{"settings":{"number_of_replicas":2}}'

##当节点数<副本数时,即多的副本没地方保存,head插件会报黄色警告。

4.recovery

5.gateway

6.discovery.zen

7.Transport

8.settings和mappings

settings:可指定副本和分片

mappings很多解释的是指定数据类型后,不按照此类型则数据插入失败。但我测试依然可以。

curl -XPUT 'http://localhost:9200/megacorp' -d '
{
    "settings": {
        "number_of_shards": 5,
        "number_of_replicas": 1
    }, 
    "mappings": {
        "employee": {
            "properties": {
                "first_name": {
                    "type": "string"
                }, 
                "last_name": {
                    "type": "string"
                }, 
                "age": {
                    "type": "integer"
                }, 
                "about": {
                    "type": "string"
                }, 
                "interests": {
                    "type": "string"
                }, 
                "join_time": {
                    "type": "date", 
                    "format": "dateOptionalTime", 
                    "index": "not_analyzed"
                }
            }
        }
    }
}'

 

 

 

 

 

 

 

 

 

 

 

posted on 2017-05-11 16:04  老曹123  阅读(138)  评论(0)    收藏  举报

导航