1
2 레벨 중첩 (문서 당 최소 개별 값)에서 최소 (최소) 값을 찾으려고합니다.Python elasticsearch 문서 당 중첩 값의 DSL 집계/메트릭
지금까지는 검색 결과에 중첩 된 모든 값의 최소값을 계산하지만 문서별로 구분하지 않는 집계를 만들 수 있습니다.
내 예를 들어, 스키마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'
)
기본적으로 내가해야 할 일입니다 모든 중첩 된 nested1에 대한 최소 값을 얻기 위해 고유 한 myexample_id 필드가있는 각 고유 MyExample의 .foo.bar 값
이 최소값은 인덱싱 할 때 알아 내고 문서의 루트 수준에 저장해야한다고 제안하기까지했습니다. '중첩 된 '문서 나 스크립트를 사용하여 여러 수준의 agg보다 훨씬 더 많은 것을 수행 할 수 있습니다. – Val