速查表之ELK IK插件(docker镜像)简单测试

简单安装
version: "3"
services:
  elk:
    image: sebp/elk:640
    ports:
      - "5601:5601"
      - "9200:9200"
      - "5044:5044"
    restart: always
    environment:
      - ES_JAVA_OPTS=-Xms2G -Xmx2G
    volumes:
      - ${PWD}/elk/elasticsearch:/var/lib/elasticsearch

安装ik插件

查找版本
https://github.com/medcl/elasticsearch-analysis-ik/releases/

进入容器,执行elasticsearch-plugin

$ ./elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysiss
-ik/releases/download/v6.3.0/elasticsearch-analysis-ik-6.3.0.zip

查询所有索引
curl 'localhost:9200/_cat/indices?v'
创建索引

localhost:9200/people (people 索引名)

curl -X PUT \
  http://localhost:9200/people \
  -H 'content-type: application/json' \
  -d '{
    "settings": {
        "number_of_shards": 1,  //分片数默认是5
        "number_of_replicas": 1   //备份数
    },
    "mappings": {
        "man": {
            "properties": {
                "name": {
                    "type": "text"
                },
                "country": { //字段名
                    "type": "keyword"   //字段类型
                },
                "age": {
                    "type": "integer"
                },
                "date": {
                    "type": "date",
                    "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
                }
            }
        }
    }
}’

——————————结果

{
    "acknowledged": true,
    "shards_acknowledged": true,
    "index": "people"
}
获取索引
curl -X GET \
  http://localhost:9200/people \

——————————结果

{
    "people": {
        "aliases": {},
        "mappings": {
            "man": {
                "properties": {
                    "age": {
                        "type": "integer"
                    },
                    "country": {
                        "type": "keyword"
                    },
                    "date": {
                        "type": "date",
                        "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
                    },
                    "name": {
                        "type": "text"
                    }
                }
            }
        },
        "settings": {
            "index": {
                "creation_date": "1587217871713",
                "number_of_shards": "1",
                "number_of_replicas": "1",
                "uuid": "GAULFlq4QnKP__KSwX7kwA",
                "version": {
                    "created": "6040099"
                },
                "provided_name": "people"
            }
        }
    }
}
插入一条数据,替换一条数据

PUT localhost:9200/people/man/1 对应 people:索引,man:类型,1:文档id

curl -X PUT \
  http://localhost:9200/people/man/1 \
  -H 'content-type: application/json' \
  -d '{
"name":"中华人民共和国,中国",
"country":"china",
"age":"20",
"data":"2020-09-09"
}’

——————————结果

{
    "_index": "people",
    "_type": "man",
    "_id": "1",
    "_version": 1,
    "result": "created",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "_seq_no": 1,
    "_primary_term": 1
}
插入一条数据自动生成id的数据

POST localhost:9200/people/man/ 自动生成id

curl -X POST \
  http://localhost:9200/people/man \
  -H 'content-type: application/json' \
  -d '{
"name":"测试,搜索",
"country":"china",
"age":"20",
"data":"1999-09-09"
}’

——————————结果

{
    "_index": "people",
    "_type": "man",
    "_id": "CW6WjXEBIKWlyvncBjJU”, //id自动生成
    "_version": 1,
    "result": "created",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "_seq_no": 0,
    "_primary_term": 1
}
更新一条数据
curl -X POST \
http://localhost:9200/people/man/Cm7RjXEBIKWlyvncdzIr/_update \
  -H 'content-type: application/json' \
  -d '{
    "doc": {
        "name": "张三"
    }
}’

——————————结果

{
    "_index": "people",
    "_type": "man",
    "_id": "Cm7RjXEBIKWlyvncdzIr",
    "_version": 2,
    "result": "updated",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "_seq_no": 4,
    "_primary_term": 1
}
根据id获取数据
curl http://localhost:9200/people/man/CW6WjXEBIKWlyvncBjJU

-------------结果

{
    "_index": "people",
    "_type": "man",
    "_id": "CW6WjXEBIKWlyvncBjJU",
    "_version": 1,
    "found": true,
    "_source": {
        "name": "测试,搜索",
        "country": "china",
        "age": "20",
        "data": "1999-09-09"
    }
}

Q1: 创建索引 报黄线
PUT http://localhost:9200/test test 为索引名
{
“settings”:{
“number_of_replincas”: 0 //es默认创建索引会是5个分片一个备份,如果备份没有机器存的话,会报yellow状态,这个设置为不需要备份
},
“mappings”:{
“dynamic”:“false”//索引结构是固定的,不要随时变动
…具体字段与类型
}
}
--------------------------------返回结果
{
“acknowledged”: true,
“shards_acknowledged”: true,
“index”: “outorder”
}

数组 可以用text es会自动识别为数组

删除索引
DELETE http://localhost:9200/test    删除模板
{
"acknowledged": true
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值