ElasticSearch如何进行嵌套范围聚合查询 [英] How does ElasticSearch do nested range aggregation query

查看:2582
本文介绍了ElasticSearch如何进行嵌套范围聚合查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

**如果在sellerInfoES的嵌套报价价格数组(嵌套数组)对象的基础上,我正在尝试汇总和查找价格范围。内部栏位是offerPrice。我如何在弹性搜索的嵌套数组字段中编写聚合。我尝试这个以下查询,但它不工作。获取此错误:解析失败[在[price_ranges]中找到两个聚合类型定义:[嵌套]和[过滤器]]



映射: / p>

  {
productsearch:{
mappings:{
product {
properties:{
brand:{
type:string
},
categories:{
类型:string
},
model:{
type:string
},
mrp:{
type:double
},
productName:{
type:string
},
rating:{
type:double
},
reviewCount:{
type:long
},
selle $ {
addr:{
type:string
} ,
country:{
type:string
},
geoAddress:{
type:string

location:{
type:string
},
offerPrice:{
type:double
},
pinCode:{
type:string
},
sellerId:{
type:long
},
sellerLocation:{
type:geo_point
},
state:{
type:string
}
}
},
sku:{
type:long
},
subCategory:{
type:string
}
}
}
}
}
}

查询: strong>

  {
price_ranges:{
嵌套:{
路径:sellerInfoES
},
aggs:{
range:{
field:offerPrice,
[
{
gte:1000
},
{
gte:1000,
lte:10000
} ,
{
gte:10000,
lte:25000
},
{
gte:25000
}
]
}
}
}
}


解决方案

您必须使用 sub_aggregation 。使用范围聚合 嵌套聚合,如:

 {
aggs:{
nested_sellerInfo:{
nested:{
path:sellerInfoES

aggs:{
offer_price_range:{
range:{
field:sellerInfoES.offerPrice,
:[
{
from:1000
},
{
from:1000,
to:10000

{
from:10000,
to:25000
},
{
from:25000
}
]
}
}
}
}
}
}
pre>

希望这有帮助!!


** I am trying to aggregate and find price ranges if on the basis of nested offer price array (nested Array) object of sellerInfoES. Internal field is "offerPrice". How I can write aggregation on the nested array field in Elasticsearch. I tried this following query, but it's not working. Getting this error: Parse Failure [Found two aggregation type definitions in [price_ranges]: [nested] and [filter]]

Mapping:

{
   "productsearch": {
      "mappings": {
         "product": {
            "properties": {
               "brand": {
                  "type": "string"
               },
               "categories": {
                  "type": "string"
               },
               "model": {
                  "type": "string"
               },
               "mrp": {
                  "type": "double"
               },
               "productName": {
                  "type": "string"
               },
               "rating": {
                  "type": "double"
               },
               "reviewCount": {
                  "type": "long"
               },
               "sellerInfoES": {
                  "type": "nested",
                  "properties": {
                     "addr": {
                        "type": "string"
                     },
                     "country": {
                        "type": "string"
                     },
                     "geoAddress": {
                        "type": "string"
                     },
                     "location": {
                        "type": "string"
                     },
                     "offerPrice": {
                        "type": "double"
                     },
                     "pinCode": {
                        "type": "string"
                     },
                     "sellerId": {
                        "type": "long"
                     },
                     "sellerLocation": {
                        "type": "geo_point"
                     },
                     "state": {
                        "type": "string"
                     }
                  }
               },
               "sku": {
                  "type": "long"
               },
               "subCategory": {
                  "type": "string"
               }
            }
         }
      }
   }
}

Query:

{
  "price_ranges": {
    "nested": {
      "path": "sellerInfoES"
    },
    "aggs": {
      "range": {
        "field": "offerPrice",
        "ranges": [
          {
            "gte": 1000
          },
          {
            "gte": 1000,
            "lte": 10000
          },
          {
            "gte": 10000,
            "lte": 25000
          },
          {
            "gte": 25000
          }
        ]
      }
    }
  }
}

解决方案

You have to use sub_aggregation. Use range aggregation inside nested aggregation like:

 {
 "aggs": {
  "nested_sellerInfo": {
     "nested": {
        "path": "sellerInfoES"
     },
     "aggs": {
        "offer_price_range": {
           "range": {
              "field": "sellerInfoES.offerPrice",
              "ranges": [
                 {
                    "from": 1000
                 },
                 {
                    "from": 1000,
                    "to": 10000
                 },
                 {
                    "from": 10000,
                    "to": 25000
                 },
                 {
                    "from": 25000
                 }
              ]
           }
         }
       }
     }
   }
  }

Hope this helps!!

这篇关于ElasticSearch如何进行嵌套范围聚合查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆