ES入门操作

创建索引

  • 创建非结构的索引:

通过postman软件,执行http请求。

put方法,

http://192.168.7.6:9200/people

body如下:

{
	"settings": {
		"number_of_shards":3,
		"number_of_replicas":1
	}
}
  • 创建结构化的索引

put方法

http://192.168.7.6:9200/people
{
	"settings": {
		"number_of_shards":3,
		"number_of_replicas":1
	},
	"mappings": {
		"man":{
			"properties":{
				"name": {
					"type": "text"
				},
				"country": {
					"type": "keyword"
				},
				"age": {
					"type": "integer"
				},
				"data": {
					"type": "date",
					"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
				}
			}
		},
		"woman": {
		}
	}
}

 

创建后,通过Elasticsearch Head观察,可以看到创建完成。

 

插入数据

  • 指定ID插入

post方法:

http://192.168.7.6:9200/people1/man/1

插入id为1的数据到people1索引

body体如下:

{
	"name": "wali",
	"country": "Chian",
	"age": 30,
	"date": "1987-03-07"
}

插入后,返回结果如下:

{
    "_index": "people1",
    "_type": "1",
    "_id": "AWpDDDpxi2_ZaFqwJNba",
    "_version": 1,
    "result": "created",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "created": true
}

通过chrome的elasticsearch head插件可以看到插入的数据:

 

  • 自动生成ID插入

post方法

http://192.168.7.6:9200/people1/man/

插入体:

{
	"name": "wali_brother1",
	"country": "china1",
	"age": 401,
	"date": "1987-08-07"
}

修改数据

post方法

http://192.168.7.6:9200/people1/man/1/_update

body体,修改name

{
	"doc":{
		"name": "whoami"
	}
}

修改数据

删除数据

delete方法删除id为1的数据

http://192.168.7.6:9200/people1/man/1

删除索引

delete方法

http://192.168.7.6:9200/monitor2018_10

 

查询

简单查询

get方法,指定id

http://192.168.7.6:9200/people1/man/3

返回结果:

{
    "_index": "people1",
    "_type": "man",
    "_id": "3",
    "_version": 1,
    "found": true,
    "_source": {
        "name": "wali_brother03",
        "country": "china",
        "age": 403,
        "date": "1987-08-22"
    }
}

 

条件查询

post方法

http://192.168.7.6:9200/people1/_search

body体:

{
	"query": {
		"match_all": {}
	}
}

默认返回10条

指定返回条数

{
	"query": {
		"match_all": {}
	},
	"size": 2
}

排序:

{
	"query": {
		"match": {
			"name": "wali"
		}
	},
	"sort": [
		{"age": {"order": "desc"}}
	]
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值