我试图找到 2 级嵌套中的最小值(每个文档单独的最小值)。
到目前为止,我能够进行聚合,计算搜索结果中所有嵌套值的最小值,但无需按文档进行分隔。
我的示例架构:
class MyExample(DocType):
myexample_id = Integer()
nested1 = Nested(
properties={
'timestamp': Date(),
'foo': Nested(
properties={
'bar': Float(),
}
)
}
)
nested2 = Nested(
multi=False,
properties={
'x': String(),
'y': String(),
}
)
这就是我搜索和聚合的方式:
from elasticsearch_dsl import Search, Q
search = Search().filter(
'nested', path='nested1', inner_hits={},
query=Q(
'range', **{
'nested1.timestamp': {
'gte': exampleDate1,
'lte': exampleDate2
}
}
)
).filter(
'nested', path='nested2', inner_hits={'name': 'x'},
query=Q(
'term', **{
'nested2.x': x
}
)
).filter(
'nested', path='nested2', inner_hits={'name': 'y'},
query=Q(
'term', **{
'nested2.y': y
}
)
)
search.aggs.bucket(
'nested1', 'nested', path='nested1'
).bucket(
'nested_foo', 'nested', path='nested1.foo'
).metric(
'min_bar', 'min', field='nested1.foo.bar'
)
基本上我需要做的是获取每个唯一 MyExample 的所有嵌套的nested1.foo.bar 值的最小值(它们具有唯一的 myexample_id 字段)