真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

ElasticSearch中g(shù)roupby+avg+sort等聚合分析是什么樣的

本篇文章為大家展示了ElasticSearch中g(shù)roup by + avg + sort等聚合分析是什么樣的,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。

創(chuàng)新互聯(lián)秉承實(shí)現(xiàn)全網(wǎng)價(jià)值營(yíng)銷的理念,以專業(yè)定制企業(yè)官網(wǎng),成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì),小程序定制開發(fā),網(wǎng)頁設(shè)計(jì)制作,成都手機(jī)網(wǎng)站制作,網(wǎng)絡(luò)營(yíng)銷推廣幫助傳統(tǒng)企業(yè)實(shí)現(xiàn)“互聯(lián)網(wǎng)+”轉(zhuǎn)型升級(jí)專業(yè)定制企業(yè)官網(wǎng),公司注重人才、技術(shù)和管理,匯聚了一批優(yōu)秀的互聯(lián)網(wǎng)技術(shù)人才,對(duì)客戶都以感恩的心態(tài)奉獻(xiàn)自己的專業(yè)和所長(zhǎng)。

將文本fields的Fielddata屬性設(shè)置true

PUT http://{{es-host}}/ecommerce/_mapping/produce
{
	"properties":{
		"tags":{
			"type":"text",
			"fielddata":true
		}
	}
}

1、計(jì)算每個(gè)tag下的商品數(shù)量

GET http://{{es-host}}/ecommerce/produce/_search
{
	"size":0,
	"aggs":{
		"group_by_tags":{
			"terms":{
				"field":"tags"
			}
		}
	}
}

group_by_tags 代表聚合分組名稱,可以隨意寫,表述清楚含義即可;

field的值對(duì)應(yīng)要聚合的字段

結(jié)果:

{
    "took": 43,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 4,
        "max_score": 0,
        "hits": []
    },
    "aggregations": {
        "group_by_tags": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {
                    "key": "fangzhu",
                    "doc_count": 2
                },
                {
                    "key": "meibai",
                    "doc_count": 2
                },
                {
                    "key": "qingxin",
                    "doc_count": 1
                }
            ]
        }
    }
}

2、按商品名稱搜索并聚合

GET http://{{es-host}}/ecommerce/produce/_search
{
	"query":{
		"match_phrase":{
			"name":"yagao"
		}
	},
	"aggs":{
		"group_by_tags":{
			"terms":{
				"field":"tags"
			}
		}
	},
	"size":0
}

檢索結(jié)果:

{
    "took": 17,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 4,
        "max_score": 0,
        "hits": []
    },
    "aggregations": {
        "group_by_tags": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {
                    "key": "fangzhu",
                    "doc_count": 2
                },
                {
                    "key": "meibai",
                    "doc_count": 2
                },
                {
                    "key": "qingxin",
                    "doc_count": 1
                }
            ]
        }
    }
}

3、先分組,再計(jì)算每個(gè)分組的平均值

GET http://{{es-host}}/ecommerce/produce/_search
{
	"size":0,
	"aggs":{
		"group_by_tags":{
			"terms":{
				"field":"tags"
			},
			"aggs":{
				"avg_price":{
					"avg":{
						"field":"price"
					}
				}
			}
		}
	}
}

結(jié)果:

{
    "took": 83,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 4,
        "max_score": 0,
        "hits": []
    },
    "aggregations": {
        "group_by_tags": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {
                    "key": "fangzhu",
                    "doc_count": 2,
                    "avg_price": {
                        "value": 27.5
                    }
                },
                {
                    "key": "meibai",
                    "doc_count": 2,
                    "avg_price": {
                        "value": 40
                    }
                },
                {
                    "key": "qingxin",
                    "doc_count": 1,
                    "avg_price": {
                        "value": 40
                    }
                }
            ]
        }
    }
}

上述內(nèi)容就是ElasticSearch中g(shù)roup by + avg + sort等聚合分析是什么樣的,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。


網(wǎng)頁題目:ElasticSearch中g(shù)roupby+avg+sort等聚合分析是什么樣的
本文鏈接:http://weahome.cn/article/ggdojc.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部