내부 개체가있는 데이터를 집계하려고합니다. 예를 들어 :ElasticSearch 1x - 개체 조건에 대한 집계
{
"_index": "product_index-en",
"_type": "elasticproductmodel",
"_id": "000001111",
"_score": 6.3316255,
"_source": {
"productId": "11111111111",
"productIdOnlyLetterAndDigit": "11111111111",
"productIdOnlyDigit": "11111111111",
"productNumber": "11111111111",
"name": "Glow Plug",
"nameOnlyLetterAndDigit": "glowplug",
"productImageLarge": "11111111111.jpg",
"itemGroupId": "11111",
"relatedProductIds": [],
"dataAreaCountries": [
"fra",
"pol",
"uk",
"sie",
"sve",
"atl",
"ita",
"hol",
"dk"
],
"oemItems": [
{
"manufactorName": "BERU",
"manufacType": "0"
},
{
"manufactorName": "LUCAS",
"manufacType": "0"
}
]
}
}
내가 할 수 집계 oemItems.manufactorName 값이 될 필요가 있지만 oemItems.manufacType은 "0"입니다. 여기에 수락 된 예 (Elastic Search Aggregate into buckets on conditions)와 같은 많은 예제를 시도했지만, 그저 내 머리를 감쌀 수없는 것 같습니다.
필자는 manufacType을 먼저 수행하고, 각 유형에 대해 manufactorName을 사용하여 올바른 적중 횟수를 표시하는 것으로 보았습니다. 그러나 manufactorName 버킷이 비어 있습니다
GET /product_index-en/_search
{
"size": 0,
"aggs": {
"baked_goods": {
"nested": {
"path": "oemItems"
},
"aggs": {
"test1": {
"terms": {
"field": "oemItems.manufacType",
"size": 500
},
"aggs": {
"test2": {
"terms": {
"field": "oemItems.manufactorName",
"size": 500
}
}
}
}
}
}
}
}
그리고 결과 :
{
"took": 27,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 471214,
"max_score": 0,
"hits": []
},
"aggregations": {
"baked_goods": {
"doc_count": 677246,
"test1": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "0",
"doc_count": 436557,
"test2": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}
},
{
"key": "1",
"doc_count": 240689,
"test2": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}
}
]
}
}
}
}
가 나는 또한 단지 쿼리를 다음과 같이 manufacType 일이있는 oemItems 볼에, 중첩 된 용어 필터를 추가하기 위해 노력했다. 그러나 oemItems에 manufacType 1이 포함되어있는 객체를 반환합니다. 즉, 제품 내의 oemItems에는 여전히 1 또는 0 개의 manufacType이 있습니다. 나는 oemItems.manufacType 지금까지 0
GET /product_index-en/_search
{
"query" : { "match_all" : {} },
"filter" : {
"nested" : {
"path" : "oemItems",
"filter" : {
"bool" : {
"must" : [
{
"term" : {"oemItems.manufacType" : "1"}
}
]
}
}
}
}
}
먼저 'oemItems'가 매핑에'중첩 된'유형인지 확인해야합니다. 그럴까요? – Val
@Val 아니요, 중첩 형식이 아닙니다. 나는 그것을 바꿀 것이고 그것이 도움이되는지 알게 될 것이다. –
@Val 중첩 된 것으로 설정하고 내 게시물에 예제를 추가했습니다. –