ElasticSearch 学习第一步

ElasticSearch 学习第一步

ElasticSearch教程——Kibana简单操作ES

对于 ElasticSearch ,是一种文档类型数据库,然而不仅仅是存储,可以对文档(而非成行成列的数据)进行索引、搜索、排序、过滤。

在Elasticsearch中,文档归属于一种类型(type),而这些类型存在于索引(index)中,我们可以对比图来类比传统关系型数据库:

 Relational DB -> Databases -> Tables -> Rows -> Columns
 Elasticsearch -> Indices   -> Types  -> Documents -> Fields
Elasticsearch集群可以包含多个索引(indices)(数据库),每一个索引可以包含多个类型(types)(表),
每一个类型包含多个文档(documents)(行),然后每个文档包含多个字段(Fields)(列)。

首先根据公司已经给出的环境,做学习任务及测试

http://******:9200/ 便是搭建 ElasticSearch 后可操作的 URL

  1. 目前需要创建一个 menhu_user 的 索引 (index),并在索引下建立一个叫 employee 的类型(type),而且还要增加文档(document)为 1 的一行数据,数据内容及增加格式如下:

        //最好使用 kibana 来玩这个东西。
        http://*******:9200/
        PUT /menhu_user/employee/1
        {
            "first_name":"men",
            "last_name":"hu",
            "age":"18",
            "sex":"boy",
            "about":"i like tongliy,i am handsome",
            "interests":[ "sports", "music" ],
            "bath":"2009-09-20"
        }

    添加之后就会出现如下信息

    
    /*#! Deprecation: the default number of shards will change from [5] to [1] in 7.0.0; if you wish to continue using the default of [5] shards, you must manage this on the create index request or with an index template*/
        {
          "_index" : "menhu_user",
          "_type" : "employee",
          "_id" : "1",
          "_version" : 1,
          "result" : "created",
          "_shards" : {
            "total" : 2,
            "successful" : 1,
            "failed" : 0
          },
          "_seq_no" : 0,
          "_primary_term" : 1
        }

    然后查询自己刚刚创建的索引 'menhu_user'

    http://******:9200/
    
    GET /menhu_user
    
    {
      "menhu_user" : {                    //索引
        "aliases" : { },                //?
            "mappings" : {
              "employee" : {            //文档
                "properties" : {
                  "about" : {            //字段
                    "type" : "text",    // 字段类型 -- 用于全文搜索,可分词,用于构建索引
                    "fields" : {       // 实现 multi-fields(一个字段,多种数据类型),通过 fields 为该字段定义 keyword 类型,用于排序和聚合
                      "keyword" : {
                        "type" : "keyword",
                        "ignore_above" : 256 //设置能被索引的字段的长度
                      }
                    }
                  },
                  "age" : {                //字段
                    "type" : "text",
                    "fields" : {
                      "keyword" : {
                        "type" : "keyword",
                        "ignore_above" : 256
                      }
                    }
                  },
                  "bath" : {            //字段
                    "type" : "date"
                  },
                  "first_name" : {        //字段
                    "type" : "text",
                    "fields" : {
                      "keyword" : {
                        "type" : "keyword",
                        "ignore_above" : 256
                      }
                    }
                  },
                  "interests" : {        //字段
                    "type" : "text",
                    "fields" : {
                      "keyword" : {
                        "type" : "keyword",
                        "ignore_above" : 256
                      }
                    }
                  },
                  "last_name" : {        //字段
                    "type" : "text",
                    "fields" : {
                      "keyword" : {
                        "type" : "keyword",
                        "ignore_above" : 256
                      }
                    }
                  },
                  "sex" : {                //字段
                    "type" : "text",
                    "fields" : {
                      "keyword" : {
                        "type" : "keyword",
                        "ignore_above" : 256
                      }
                    }
                  }
                }
              }
            },
            "settings" : {
              "index" : {
                "creation_date" : "1564112130193",
                "number_of_shards" : "5",
                "number_of_replicas" : "1",
                "uuid" : "AvvameEPTa-Y5g_AXLTjRg",
                "version" : {
                  "created" : "6060099"
                },
                "provided_name" : "menhu_user"
              }
            }
          }
        }

    接下来可以创建 第二 、第三条 人员信息。

        http://******:9200/
        PUT /menhu_user/employee/2
        {
            "first_name":"li",
            "last_name":"hua",
            "age":"28",
            "sex":"old boy",
            "about":"从来没有上过厕所,后来非常不幸的结石了",
            "interests":[ "game", "music" ],
            "bath":"1899-09-20"
        }
    
  2. 建立完数据之后
有的地方可能引用了别人的文章,如果涉及侵权,请联系我删除

你可能感兴趣的:(elasticsearch)