2

根据官方文档,似乎只能对单桶聚合进行排序。如何按桶聚合数量中的“平均”对结果进行排序?

我在 'result_1' 中添加了 'order' 仍然无法正常工作。它在下面显示错误:

TransportError(500, u'search_phase_execution_exception')
Invalid terms aggregation order path [reverse>condi_range>statistic_score.avg]. 
Terms buckets can only be sorted on a sub-aggregator path that is built out of zero or more single-bucket aggregations within the path and a final single-bucket or a metrics aggregation at the path end. 
Sub-path [reverse>condi_range] points to non single-bucket aggregation')

关键是我必须限制'float_field'的范围,范围聚合是另一个桶聚合。

有人有什么主意吗?

谢谢!

代码示例:

{
  "aggs": {
    "condi_nested": {
      "aggs": {
        "filtered": {
          "filter": {
            "bool": {}
          },
          "aggs": {
            "result_1": {
              "terms": {
                "field": "Foo",
                "size": 100000000,
                "order": {
                  "reverse>condi_range>statistic_score.avg": "desc"
                }
              },
              "aggs": {
                "reverse": {
                  "aggs": {
                    "condi_range": {
                      "range": {
                        "ranges": [
                          {
                            "to": 100,
                            "from": 0
                          }
                        ],
                        "field": "float_field"
                      },
                      "aggs": {
                        "percentile_score": {
                          "percentiles": {
                            "field": "float_field"
                          }
                        },
                        "statistic_score": {
                          "extended_stats": {
                            "field": "float_field"
                          }
                        }
                      }
                    }
                  },
                  "reverse_nested": {}
                }
              }
            }
          }
        }
      },
      "nested": {
        "path": "nested_path_of_Foo"
      }
    }
  }
}
4

1 回答 1

0

我只是想知道问题出在哪里。

使用“过滤器”替换“范围”

{
  "aggs": {
    "condi_range": {
      "filter": {
        "range": {
          "float_field": {
            "gte": 0,
            "lte": 100
          }
        }
      },
      "aggs":{
        ...blahblahblah...
      }
    }
  }
}

但是在我问的问题之后我发现了另一个问题。

我无法在嵌套聚合后对字段进行排序,引发问题中发布的相同错误。

这是示例:

{
  "aggs": {
    "result_1": {
      "terms": {
        "field": "Foo",
        "order": {
          "condi_nested>filtered>condi_range>statistic_score.min": "desc"
        },
        "size": 100000000
      },
      "aggs": {
        "condi_nested": {
          "aggs": {
            "filtered": {
              "filter": {
                "bool": {}
              },
              "aggs": {
                "condi_range": {
                  "filter": {
                    "range": {
                      "nested_path_of_float_field.float_field": {
                        "gte": 0,
                        "lte": 100
                      }
                    }
                  },
                  "aggs": {
                    "statistic_score": {
                      "extended_stats": {
                        "field": "nested_path_of_float_field.float_field"
                      }
                    }
                  }
                }
              }
            }
          },
          "nested": {
            "path": "nested_path_of_float_field"
          }
        }
      }
    }
  }
}

和这个

{
  "aggs": {
    "condi_nested": {
      "aggs": {
        "filtered": {
          "filter": {
            "bool": {}
          },
          "aggs": {
            "result_1": {
              "terms": {
                "field": "Foo",
                "order": {
                  "reverse>condi_nested>condi_range>statistic_score.min": "desc"
                },
                "size": 100000000
              },
              "aggs": {
                "reverse": {
                  "aggs": {
                    "condi_nested": {
                      "aggs": {
                        "condi_range": {
                          "filter": {
                            "range": {
                              "nested_path_of_float_field.float_field": {
                                "gte": 0,
                                "lte": 100
                              }
                            }
                          },
                          "aggs": {
                            "percentile_score": {
                              "percentiles": {
                                "field": "nested_path_of_float_field.float_field"
                              }
                            },
                            "statistic_score": {
                              "extended_stats": {
                                "field": "nested_path_of_float_field.float_field"
                              }
                            }
                          }
                        }
                      },
                      "nested": {
                        "path": "nested_path_of_float_field"
                      }
                    }
                  },
                  "reverse_nested": {}
                }
              }
            }
          }
        }
      },
      "nested": {
        "path": "nested_path_of_Foo"
      }
    }
  }
}
于 2016-06-29T05:51:46.850 回答