轻松学会Elasticsearch+kibana

轻松学会Elasticsearch+kibana

  • 1、创建模板
  • 2、测试获取模板
  • 3、删除模板
  • 4、创建索引
  • 5、查看索引
  • 6、给已有索引增加字段
  • 7、给新增字段初始值
  • 8、删除索引

1、创建模板

PUT _template/test
{
  "template": "test*",
  "mappings": {
    "properties": {
      "id": { "type": "integer" },
      "name": { "type": "keyword" }
    }
  }
}

返回值

{
  "acknowledged" : true
}

2、测试获取模板

GET _template/test

返回值

{
  "test" : {
    "order" : 0,
    "index_patterns" : [
      "test*"
    ],
    "settings" : { },
    "mappings" : {
      "properties" : {
        "name" : {
          "type" : "keyword"
        },
        "id" : {
          "type" : "integer"
        }
      }
    },
    "aliases" : { }
  }
}

3、删除模板

DELETE _template/test

返回值

{
  "acknowledged" : true
}

4、创建索引

PUT test
{
   "settings": {
        "number_of_shards": 3,
        "number_of_replicas": 2
      }
}

返回值

{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "test"
}

5、查看索引

GET test

返回值

{
  "test" : {
    "aliases" : { },
    "mappings" : {
      "properties" : {
        "id" : {
          "type" : "integer"
        },
        "name" : {
          "type" : "keyword"
        }
      }
    },
    "settings" : {
      "index" : {
        "creation_date" : "1702458256558",
        "number_of_shards" : "3",
        "number_of_replicas" : "2",
        "uuid" : "EnJWQWRRSViuNxiTYoFE3w",
        "version" : {
          "created" : "7040099"
        },
        "provided_name" : "test"
      }
    }
  }
}

6、给已有索引增加字段

PUT test/_mapping
{
  "properties": {
    "is_collect": {
      "type": "integer"
    }
  }
}

返回值

{
  "acknowledged" : true
}

再次查看确认即可看到新增的字段

{
  "test" : {
    "aliases" : { },
    "mappings" : {
      "properties" : {
        "id" : {
          "type" : "integer"
        },
        "is_collect" : {
          "type" : "integer"
        },
        "name" : {
          "type" : "keyword"
        }
      }
    },
    "settings" : {
      "index" : {
        "creation_date" : "1702458256558",
        "number_of_shards" : "3",
        "number_of_replicas" : "2",
        "uuid" : "EnJWQWRRSViuNxiTYoFE3w",
        "version" : {
          "created" : "7040099"
        },
        "provided_name" : "test"
      }
    }
  }
}

7、给新增字段初始值

示例中更没有加任何筛选条件,默认是全部数据初始化值为2
修改数据请慎重!!!!!!

POST test/_update_by_query
{
  "script": {
    "source": "ctx._source.is_collect = 2"
  },
  "query": {
    "match_all": {}
  }
}

返回值

{
  "took" : 4,
  "timed_out" : false,
  "total" : 0,
  "updated" : 0,
  "deleted" : 0,
  "batches" : 0,
  "version_conflicts" : 0,
  "noops" : 0,
  "retries" : {
    "bulk" : 0,
    "search" : 0
  },
  "throttled_millis" : 0,
  "requests_per_second" : -1.0,
  "throttled_until_millis" : 0,
  "failures" : [ ]
}

8、删除索引

DELETE test

返回值

{
  "acknowledged" : true
}

你可能感兴趣的:(Elasticsearch,elasticsearch,大数据,搜索引擎,kibana)