gpt4 book ai didi

elasticsearch - ElasticSearch 1x-在对象条件下聚合

转载 作者:行者123 更新时间:2023-12-03 01:54:06 25 4
gpt4 key购买 nike

我想聚合具有内部对象的数据。例如:

{
"_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 1的oemItems。但是,它返回oemItems包含manufacType 1的对象,这意味着产品中的oemItems仍包含1或0 manufacType。我看不到如何对此响应进行汇总将仅返回oemItems.manufactorName,其中oemItems.manufacType为0
GET /product_index-en/_search 
{
"query" : { "match_all" : {} },
"filter" : {
"nested" : {
"path" : "oemItems",
"filter" : {
"bool" : {
"must" : [
{
"term" : {"oemItems.manufacType" : "1"}
}
]
}
}
}
}
}

最佳答案

到目前为止良好的开端。像这样尝试一下:

POST /product_index-en/_search
{
"size": 0,
"query": {
"nested": {
"path": "oemItems",
"query": {
"term": {
"oemItems.manufacType": "0"
}
}
}
},
"aggs": {
"baked_goods": {
"nested": {
"path": "oemItems"
},
"aggs": {
"test1": {
"terms": {
"field": "oemItems.manufactorName",
"size": 500
}
}
}
}
}
}

关于elasticsearch - ElasticSearch 1x-在对象条件下聚合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37937274/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com