我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

elasticsearch嵌套查询聚合数据

先展示数据结构如下:

在金台等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都网站设计、做网站 网站设计制作定制开发,公司网站建设,企业网站建设,品牌网站建设,成都营销网站建设,成都外贸网站制作,金台网站建设费用合理。

{
"itemId": "132417862061",
"site": "US",
"sellerId": "aaaaa",
"increamentId": "3753595",
"ebayTrackList": [
	{
		"numCount": 0,
		"pageView": 1,
		"userView": 1,
		"amountPaid": 0,
		"conversionRate": 0,
		"date": "2017-12-15"
	},
	{
		"numCount": 0,
		"pageView": 1,
		"userView": 1,
		"amountPaid": 0,
		"conversionRate": 0,
		"date": "2017-12-29"
	},
	{
		"numCount": 0,
		"pageView": 1,
		"userView": 1,
		"amountPaid": 0,
		"conversionRate": 0,
		"date": "2018-02-03"
	},
	{
		"numCount": 0,
		"pageView": 1,
		"userView": 1,
		"amountPaid": 0,
		"conversionRate": 0,
		"date": "2018-03-12"
	},
	{
		"numCount": 0,
		"pageView": 1,
		"userView": 1,
		"amountPaid": 0,
		"conversionRate": 0,
		"date": "2018-03-20"
	},
	{
		"numCount": 0,
		"pageView": 1,
		"userView": 1,
		"amountPaid": 0,
		"conversionRate": 0,
		"date": "2018-03-24"
	},
	{
		"numCount": 0,
		"pageView": 2,
		"userView": 1,
		"amountPaid": 0,
		"conversionRate": 0,
		"date": "2018-04-01"
	},
	{
		"numCount": 0,
		"pageView": 1,
		"userView": 1,
		"amountPaid": 0,
		"conversionRate": 0,
		"date": "2018-04-02"
	}
],
"publisher": "2714",
"title": "MOTOSPEED LED Backlight 87 keys Bluetooth Mechanical Keyboard Red Switches T1W8",
"sku": [
"C5060"
],
"img": "/upload/otherpic58/153898.jpg",
"price": 55.05,
"status": 1,
"currency": "USD",
"createTime": "1512074612",
"updateTime": "1522694170",
"mark": null,
"fromCountry": "Shen Zhen",
"oldSku": null
}

目前的需求是假如我要知道2018-04-02,2018-04-03号的pageView之和,很明显需要ebayTrackList.date过滤求和ebayTrackList.pageView字段

语句如下

{
	"query":{
		"bool" : {
            		"must" : [
            			{
            				"term" : {"itemId":"132417862061"}
            			},
            			{
            				"nested" : {
            					"path" : "ebayTrackList",
            					"query" : {
            						"bool" : {
            							"must" : [
            								{ "terms" : {"ebayTrackList.date" : ["2018-04-03","2018-04-02"]} }
            							]
            						}
            					}
            				}
            			}
            		]
		}
	},
	"aggs":{
		"numTotalCount" : {
                        "nested" : {
                            "path" : "ebayTrackList"
                        },
                        "aggs" : {
                        	"sd_value" : {
                        		"filter" : { "terms" : {"ebayTrackList.date" : ["2018-04-03","2018-04-02"]} },
                        		"aggs" : {
                        			"sum_count" : { "sum" : { "field" : "ebayTrackList.pageView" } }
                        		}
                        	}
                        }
        }
	}
}

本文题目:elasticsearch嵌套查询聚合数据
网站路径:http://mswzjz.cn/article/joscsi.html

其他资讯