您的位置:首页 > 其它

Elasticsearch 5.4.3 聚合分组实战演练

2018-02-02 17:36 323 查看
GET /my_index/my_type/_search

{

"query": {

"fuzzy": {

"text":{

"value": "surprize",

"fuzziness": 6

}

}

}

}

GET /my_index/my_type/_search

{

"query": {

"fuzzy": {

"text":{

"value": "surprize",

"fuzziness": 5

}

}

}

}

GET /my_index/my_type/_search

{

"query": {

"match": {

"text": {

"query": "SURPIZE ME",

"fuzziness": "AUTO",

"operator": "and"

}

}

}

}

GET /my_index/my_type/_search

{

"query": {

"match": {

"text": {

"query": "SURPIZE ME",

"fuzziness": "AUTO",

"operator": "and"

}

}

}

}

PUT my_index

{

"mappings": {

"my_type":{

"properties": {

"text": {

"type":"text",

"analyzer":"ik_max_word"

}

}

}

}

}

POST /my_index/my_type/_bulk

{ "index": { "_id": "1"} }

{ "text": "男子偷上万元发红包求交女友 被抓获时仍然单身" }

{ "index": { "_id": "2"} }

{ "text": "16岁少女为结婚“变”22岁 7年后想离婚被法院拒绝" }

{ "index": { "_id": "3"} }

{ "text": "深圳女孩骑车逆行撞奔驰 遭索赔被吓哭(图)" }

{ "index": { "_id": "4"} }

{ "text": "女人对护肤品比对男票好?网友神怼" }

{ "index": { "_id": "5"} }

{ "text": "为什么国内的街道招牌用的都是红黄配?" }

GET /my_index/my_type/_search

{

"query": {

"match": {

"text": "16岁少女结婚好还是单身好"

}

}

}

GET /my_index/_analyze

{

"text": "男子偷上万元发红包求交女友 被抓获时仍然单身",

"analyzer": "ik_max_word"

}

GET /my_index/_analyze

{

"text":"深圳女孩骑车逆行撞奔驰 遭索赔被吓哭(图)",

"analyzer": "ik_max_word"

}

GET _analyze

{

"text": "啥蓝瘦香菇",

"analyzer": "ik_max_word"

}

PUT /tvs

{

"mappings": {

"sales": {

"properties": {

"price": {

"type": "long"

},

"color": {

"type": "keyword"

},

"brand": {

"type": "keyword"

},

"sold_date": {

"type": "date"

}

}

}

}

}

POST /tvs/sales/_bulk

{ "index": {}}

{ "price" : 1000, "color" : "红色", "brand" : "长虹", "sold_date" : "2016-10-28" }

{ "index": {}}

{ "price" : 2000, "color" : "红色", "brand" : "长虹", "sold_date" : "2016-11-05" }

{ "index": {}}

{ "price" : 3000, "color" : "绿色", "brand" : "小米", "sold_date" : "2016-05-18" }

{ "index": {}}

{ "price" : 1500, "color" : "蓝色", "brand" : "TCL", "sold_date" : "2016-07-02" }

{ "index": {}}

{ "price" : 1200, "color" : "绿色", "brand" : "TCL", "sold_date" : "2016-08-19" }

{ "index": {}}

{ "price" : 2000, "color" : "红色", "brand" : "长虹", "sold_date" : "2016-11-05" }

{ "index": {}}

{ "price" : 8000, "color" : "红色", "brand" : "三星", "sold_date" : "2017-01-01" }

{ "index": {}}

{ "price" : 2500, "color" : "蓝色", "brand" : "小米", "sold_date" : "2017-02-12" }

GET /tvs/sales/_search

{

"size": 0,

"aggs": {

"colour": {

"terms": {

"field": "color"

}

}

}

}

GET /tvs/sales/_search

{

"size" : 0,

"aggs": {

"colors": {

"terms": {

"field": "color"

},

"aggs": {

"avg_price": {

"avg": {

"field": "price"

}

}

}

}

}

}

GET /tvs/sales/_search

{

"size": 0,

"aggs": {

"color": {

"terms": {

"field": "color"

},

"aggs": {

"price": {

"avg": {

"field": "price"

}

}

}

}

}

}

GET /tvs/sales/_search

{

"size": 0,

"aggs": {

"color": {

"terms": {

"field": "color"

},

"aggs": {

"price": {

"avg": {

"field": "price"

}

},

"terms": {

"field": "brand"

},

"aggs": {

"price": {

"avg": {

"field": "price"

}

}

}

}

}

}

}

GET /tvs/sales/_search

{

"size": 0,

"aggs": {

"group_by_color": {

"terms": {

"field": "color"

},

"aggs": {

"color_avg_price": {

"avg": {

"field": "price"

}

},

"group_by_brand": {

"terms": {

"field": "brand"

},

"aggs": {

"brand_avg_price": {

"avg": {

"field": "price"

}

}

}

}

}

}

}

}

GET /tvs/sales/_search

{

"size": 0,

"aggs": {

"color": {

"terms": {

"field": "color"

},

"aggs": {

"price": {

"avg": {

"field": "price"

}

},

"group_brand":{

"terms": {

"field": "brand"

},

"aggs": {

"brand_price": {

"avg": {

"field": "price"

}

}

}

}

}

}

}

}

GET /tvs/sales/_search

{

"size": 0,

"aggs": {

"colors": {

"terms": {

"field": "color"

},

"aggs": {

"avg_price": {

"avg": {

"field": "price"

}

},

"min_price": {

"min": {

"field": "price"

}

},

"max_price": {

"max": {

"field": "price"

}

},

"sum_price": {

"sum": {

"field": "price"

}

}

}

}

}

}

GET /tvs/sales/_search

{

"size": 0,

"aggs": {

"color": {

"terms": {

"field": "color"

},

"aggs": {

"avg_price": {

"avg": {

"field": "price"

}

},

"min_price":{

"min": {

"field": "price"

}

},

"max_price":{

"max": {

"field": "price"

}

},

"sum_price":{

"sum": {

"field": "price"

}

}

}

}

}

}

GET /tvs/sales/_search

{

"size": 0,

"aggs": {

"group_by_price": {

"histogram": {

"field": "price",

"interval": 2000

},

"aggs": {

"sum_price": {

"sum": {

"field": "price"

}

}

}

}

}

}

GET /tvs/sales/_search

{

"size": 0,

"aggs": {

"sale": {

"date_histogram": {

"field": "sold_date",

"interval": "month",

"format": "yyyy-MM-dd",

"min_doc_count": 0,

"extended_bounds" : {

"min" : "2016-01-01",

"max" : "2017-12-31"

}

}

}

}

}

GET /tvs/sales/_search

{

"size": 0,

"aggs": {

"group_by_sold_date": {

"date_histogram": {

"field": "sold_date",

"interval": "quarter",

"format": "yyyy-MM-dd",

"min_doc_count": 0,

"extended_bounds": {

"min": "2016-01-01",

"max": "2017-12-31"

}

},

"aggs": {

"group_by_brand": {

"terms": {

"field": "brand"

},

"aggs": {

"sum_price": {

"sum": {

"field": "price"

}

}

}

},

"total_sum_price": {

"sum": {

"field": "price"

}

}

}

}

}

}

GET /tvs/sales/_search

{

"size": 0,

"query": {

"term": {

"brand":{

"value":"小米"

}

}

},

"aggs": {

"color": {

"terms": {

"field": "color"

}

}

}

}

GET /tvs/sales/_search

{

"size": 0,

"query": {

"term": {

"brand": {

"value": "长虹"

}

}

},

"aggs": {

"group_by_price": {

"avg": {

"field": "price"

}

},

"all":{

"global": {},

"aggs": {

"price": {

"avg": {

"field": "price"

}

}

}

}

}

}

GET /tvs/sales/_search

{

"size": 0,

"query": {

"constant_score": {

"filter": {

"range": {

"price": {

"gte": 1200

}

}

}

}

},

"aggs": {

"avg_price": {

"avg": {

"field": "price"

}

}

}

}

GET /tvs/sales/_search

{

"size": 0,

"query": {

"constant_score": {

"filter": {

"range": {

"price": {

"gte": 1200

}

}

}

}

},

"aggs": {

"price": {

"avg": {

"field": "price"

}

}

}

}

GET /tvs/sales/_search

{

"size": 0,

"query": {

"term": {

"brand": {

"value": "长虹"

}

}

},

"aggs": {

"recent_150d": {

"filter": {

"range": {

"sold_date": {

"gte": "now-150d"

}

}

},

"aggs": {

"recent_150d_avg_price": {

"avg": {

"field": "price"

}

}

}

},

"recent_140d": {

"filter": {

"range": {

"sold_date": {

"gte": "now-140d"

}

}

},

"aggs": {

"recent_140d_avg_price": {

"avg": {

"field": "price"

}

}

}

},

"recent_130d": {

"filter": {

"range": {

"sold_date": {

"gte": "now-130d"

}

}

},

"aggs": {

"recent_130d_avg_price": {

"avg": {

"field": "price"

}

}

}

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: