新增带id ducument
POST customer_info/_doc/1
{
"customerName":"大连集团",
"telephone":"18963608741",
"address":"江苏省南京市浦口区"
}
新增自动生成id document
POST customer_info/_doc
{
"customerName":"阿里集团",
"telephone":"1812345123",
"address":"浙江省杭州市"
}
POST customer_info/_doc
{
"customerName":"腾讯集团",
"telephone":"1111111111",
"address":"广东省深圳市"
}
POST customer_info/_doc
{
"customerName":"华为集团",
"telephone":"2222222222",
"address":"广东省深圳市"
}
批量新增数据
POST /tanshi/_bulk
{"index":{}}
{"contents":"锄禾日蛋午,上山打老虎","author":"王小二","id":232,"type":"五言绝句","title":"打油诗"}
更新id=1数据
POST customer_info/_doc/1
{
"customerName":"大连集团2",
"telephone":"18963608741",
"address":"江苏省南京市浦口区"
}
修改指定字段数据
POST customer_info/_update/1
{
"doc": {
"telephone":"110"
}
}
删除单条数据
DELETE customer_info/_doc/1
查询数据
GET customer_info/_search
match query,match_phrase query,match_phrase_prefix query对比
1)match query:用于执行全文查询的标准查询,包括模糊匹配和短语或接近查询。重要参数:控制Token之间的布尔关系:operator:or/and
2)match_phrase query:与match查询类似,但用于匹配确切的短语或单词接近匹配。重要参数:Token之间的位置距离:slop 参数
3)match_phrase_prefix query(一般不用,性能差):与match_phrase查询类似,但是会对最后一个Token在倒排序索引列表中进行通配符搜索。重要参数:模糊匹配数控制:max_expansions 默认值50,最小值为1
## 查询match
有分词效果,能够查询腾x讯,讯腾
```bash
GET customer_info/_search
{
"query": {
"match": {
"customerName": "腾讯"
}
}
}
查询 match_phrase
mysql like效果
GET customer_info/_search
{
"query": {
"match_phrase": {
"customerName": "讯"
}
}
}
查询multi_match
与match效果一样,多字段有一个匹配就返回
GET customer_info/_search
{
"query": {
"multi_match": {
"query": "腾讯",
"fields": ["customerName","address"]
}
}
}
查询 term
常⽤于结构化的数据,⽐如:number, date, keyword等,⽽不是对text。单词级别的查询⼀般⽤于数值、⽇期等类型的字段上
GET customer_info/_search
{
"query": {
"term": {
"telephone": "1812345123"
}
}
}
keyword聚合查询
# 对keyword类型field聚合查询
GET kibana_sample_data_flights/_search
{
"size": 0,
"aggs":{
"flight_dest":{
"terms":{
"field":"DestCountry"
}
}
}
}
# 找出每个DestCountry最高,平均,最低票价
GET kibana_sample_data_flights/_search
{
"size": 0,
"aggs":{
"flight_dest":{
"terms":{
"field":"DestCountry"
},
"aggs":{
"avg_price":{
"avg":{
"field":"AvgTicketPrice"
}
},
"max_price":{
"max":{
"field":"AvgTicketPrice"
}
},
"min_price":{
"min":{
"field":"AvgTicketPrice"
}
}
}
}
}
}
#价格统计信息+天气信息
GET kibana_sample_data_flights/_search
{
"size": 0,
"aggs":{
"flight_dest":{
"terms":{
"field":"DestCountry"
},
"aggs":{
"stats_price":{
"stats":{
"field":"AvgTicketPrice"
}
},
"wather":{
"terms": {
"field": "DestWeather",
"size": 5
}
}
}
}
}
}