elasticsearch 增删改查(postman)

elasticsearch 增删改查(postman)

1.建表:
创建索引和type,也就是建库建表
小飞人:PUT http://192.168.56.101:9200/mydemo(库)  关键词PUT
{
	"setting":{
		"index":{
			"number_of_shards":2,
			"number_of_replicas":1
		}	
	},
	"mappings":{
		"userinfos":{(表)
			"properties":{
				"userid":{(属性)
					"type":"string"
				},
				"username":{
					"type":"string"
				},
				"birthday":{
					"type":"date",
					"format":"yyyy-MM-dd"
				}
			}
		}
	}
}

2.删除索引(库)
DELETE  http://192.168.56.101:9200/mydemo
3.修改表中字段属性
POST  http://192.168.56.101:9200/mydemo/userinfos/_mapping
{
	"userinfos":{
		"properties":{
			"age":{
				"type":"integer"
			}
		}
	}
}

4.添加数据
POST http://192.168.56.101:9200/mydemo/userinfos对应修改字段的id
POST http://192.168.56.101:9200/mydemo/userinfos/对应修改字段的id
{
按照你设置的type格式输入,例:"stuid":1,
							"stuname":john
}
5.删除数据
DELETE http://192.168.56.101:9200/mydemo/userinfos/对应修改字段的id
上面是直接删,下面是按查询结果删
POST  http://192.168.56.101:9200/索引名/类型名/_delete_by_query
{查询语法}
6.修改数据
按照ID修改
POST http://192.168.56.101:9200/索引名/类型名/ID/_update
{
	"doc":{
		"birthday":"1999-5-9"
	}
}
7.	查询数据
关键词:GET
http://192.168.56.101:9200/索引名/类型名/ID(直接查询,不用其他语句)
其他查询
(1) GET http://IP:9200/索引名/类型名/_search
①	普通模糊查询,查找名字中带a的所有信息
{
	"query":{
		"match":{
			"username":"a"
		}
	}
}

(2) GET http://IP:9200/索引名/类型名/_search
②	短语查询
{
	"query":{
		"match_phrase":{
			"username":"ab"
		}
	}
}
(3) GET http://IP:9200/索引名/类型名/_search
③	多列查询
{
	"query":{
		"multi_match":{
			"username":"a",
			"fields":["column1","column2"]
		}
	}
}
(4) GET http://IP:9200/索引名/类型名/_search
④	分页查询
{
	"query":{
		"multi_match":{
			"username":"a",
			"fields":["column1","column2"]
		}
	},
	"from":1,
	"size":10
}
(5)GET http://IP:9200/索引名/类型名/_search
⑤	分组/聚合查询
{
	"aggs":{
		"query_by_name":{
			"terms":{
				"field":"username"
			}
		}
	}
}
{
	"aggs":{
		"query_by_name":{
			"stats":{
				"field":"username"
			}
		}
	}
}
(6) GET http://IP:9200/索引名/类型名/_search
⑥	Query string查询[Java语法常用]
{
	"query":{
		"query_string":{
			"query":"张 OR 赵 OR 李"
		}
	}
}

(7) GET http://IP:9200/索引名/类型名/_search
{
	"query":{
		"range":{
			"age":{
				"gte":15,
				"lte":20
			}
		}
	}
}

Filter查询
{
	"query":{
		"bool":{
			"filter":{
				"term":{
					"birthday":"1999-9-9"
				}
			}
		}
	}
}

复合查询(should/must/must_not)
{
	"query":{
		"bool":{
			"should":[
				{
					"match":{
						"username":"张"
					}
				},
				{
					"match":{
						"birthday":"1999-9-9"
					}
				}
			]
		}
	}
}

8.分片器
POST http://192.168.56.101:9200/_analyse
{
"analyzer":"ik_max_word",""ik_smart","standard"
"text":"我是一个中国人"
}
8.1不可拆分类型
"setting":{
		"index":{
			"number_of_shards":2,
			"number_of_replicas":1
		}	
	},
	"mappings":{
		"userinfos":{(表)
			"properties":{
				"userid":{(属性)
					"type":"keyword"(表示不可拆分)
				},
				"username":{
					"type":"keyword"
				},
				"birthday":{
					"type":"date",
					"format":"yyyy-MM-dd"
				}
			}
		}
	}
}
  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值