URL: /products/_doc/_search?routing=DEFAULT&filter_path=took,hits.hits._id,aggregations.filters..buckets.key,aggregations.filters. .buckets.key_as_string,aggregations.filters..buckets.doc_count,hits.hits._source,aggregations.filters. ..buckets.key,aggregations.filters. ..buckets.key_as_string,aggregations.filters. .*.buckets.doc_count
Body:
{
"min_score": 0.5,
"size": 500,
"_source": true,
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "test1",
"type": "best_fields",
"tie_breaker": 0.3,
"minimum_should_match": "100%",
"fields": [
"_doc_id^2",
"_doc_name",
"autocomplete_all",
"descrip1",
"descrip2",
"descrip3",
"lookup_all",
"token_all"
]
}
}
],
"should": [
{
"nested": {
"path": "filters.attributes",
"query": {
"bool": {
"should": [
{
"match": {
"filters.attributes.attributename": "operating system"
}
}
]
}
}
}
}
],
"filter": [
{
"bool": {
"must": [
{
"match": {
"tenant_id": "DEFAULT"
}
},
{
"terms": {
"cono": [
5000,
0
]
}
},
{
"terms": {
"record_type": [
"icsp"
]
}
},
{
"nested": {
"path": "filters.attributes",
"query": {
"bool": {
"should": [
{
"match": {
"filters.attributes.attributename": "operating system"
}
}
]
}
}
}
}
]
}
}
],
"must_not": [
{
"nested": {
"path": "filters",
"query": {
"bool": {
"should": [
{
"match": {
"filters.activefl": false
}
}
]
}
}
}
},
{
"nested": {
"path": "filters",
"query": {
"bool": {
"should": [
{
"match": {
"filters.statustype": "i"
}
}
]
}
}
}
}
]
}
},
"aggs": {
"filters": {
"nested": {
"path": "filters"
},
"aggs": {
"activefl": {
"terms": {
"field": "filters.activefl",
"size": 200
}
},
"attributegroup": {
"terms": {
"field": "filters.attributegroup",
"size": 200
}
},
"attributes": {
"aggs": {
"attributevalue": {
"terms": {
"field": "filters.attributes.attributevalue",
"size": 200
}
},
"attributename": {
"terms": {
"field": "filters.attributes.attributename",
"size": 200
}
}
},
"nested": {
"path": "filters.attributes"
}
}
}
}
}
}
CURRENT RESPONSE :
{
"took": 60,
"hits": {
"hits": [
{
"_id": "9defbc2a-da45-09bb-da13-8913c0f6159a",
"_source": {
"tenant_id": "DEFAULT",
"record_type": "icsp",
"cono": 5000,
"product_id": " 3 mam",
"lookupnm": "rya test",
"descrip1": "konda test ism",
"descrip2": "descrip2",
"descrip3": "test1 hello 112 apple ios 15",
"descrip1_es": "spn desc1",
"descrip2_es": "spn desc2",
"descrip3_es": "spn extdes",
"descrip1_fr": "frnch desc1",
"descrip2_fr": "frnch desc2",
"descrip3_fr": "frnch ext desc",
"transdttmz": 1732694599008,
"attributegroup": "electronics",
"attributes": [
{
"attributename": "Brand",
"attributevalue": "Apple"
},
{
"attributename": "Storage",
"attributevalue": "112"
},
{
"attributename": "Category",
"attributevalue": "C610"
},
{
"attributename": "Storage",
"attributevalue": "256"
},
{
"attributename": "Operating System",
"attributevalue": "iOS 15"
}
],
"lookup_all": "\"40\" 6pck Electronics",
"token_all": "3 mam rya test konda ism descrip2 test1 hello 112 apple ios 15 electronics",
"token_all_en": "3 mam rya test electronics",
"token_all_es": "3 mam rya test spn desc1 desc2 extdes electronics",
"token_all_fr": "3 mam rya test frnch desc1 desc2 ext desc electronics",
"filters": {
"custno": 0,
"keyno": 0,
"msdsfl": false,
"prodcat": "\"40\"",
"rectype": "icsp",
"shipto": "sx_empty",
"statustype": "L",
"unitstock": "6pck",
"whse": "sx_empty",
"attributegroup": "Electronics",
"attributes": [
{
"attributename": "Brand",
"attributevalue": "Apple"
},
{
"attributename": "Storage",
"attributevalue": "112"
},
{
"attributename": "Category",
"attributevalue": "C610"
},
{
"attributename": "Storage",
"attributevalue": "256"
},
{
"attributename": "Operating System",
"attributevalue": "iOS 15"
}
]
}
}
}
]
},
"aggregations": {
"filters": {
"attributegroup": {
"buckets": [
{
"key": "ELECTRONICS",
"doc_count": 1
}
]
},
"attributes": {
"attributevalue": {
"buckets": [
{
"key": "112",
"doc_count": 1
},
{
"key": "256",
"doc_count": 1
},
{
"key": "APPLE",
"doc_count": 1
},
{
"key": "C610",
"doc_count": 1
},
{
"key": "IOS 15",
"doc_count": 1
}
]
},
"attributename": {
"buckets": [
{
"key": "STORAGE",
"doc_count": 2
},
{
"key": "BRAND",
"doc_count": 1
},
{
"key": "CATEGORY",
"doc_count": 1
},
{
"key": "OPERATING SYSTEM",
"doc_count": 1
}
]
}
}
}
}
}
i want it in below way for aggregation for attribute name and value how?
{
"aggregations": {
"filters": {
"attributename": {
"buckets": [
{
"key": "STORAGE",
"doc_count": 2,
"attributevalue": {
"buckets": [
{
"key": "112",
"doc_count": 1
},
{
"key": "256",
"doc_count": 1
}
]
}
},
{
"key": "BRAND",
"doc_count": 1,
"attributevalue": {
"buckets": [
{
"key": "Apple",
"doc_count": 1
}
]
}
},
{
"key": "CATEGORY",
"doc_count": 1,
"attributevalue": {
"buckets": [
{
"key": "C610",
"doc_count": 1
}
]
}
},
{
"key": "OPERATING SYSTEM",
"doc_count": 1,
"attributevalue": {
"buckets": [
{
"key": "iOS 15",
"doc_count": 1
}
]
}
}
]
}
}
}
}