.Net Nest中的ElasticSearch过滤器聚合(ElasticSearch Filter Aggregation in .Net Nest)
我正在尝试通过Nest 2.3.2对ElasticSearch运行以下Filter Aggregation查询。
GET workitems_v2/mail/_search { size:0, "aggs" : { "AutoComplete" : { "filter" : { "match": { "claimData.claimOwner":"dav" } }, "aggs": { "Suggestions": { "terms": {"field":"claimData.claimOwner.raw"} } } } } }
这是我在Nest(VB.Net)中的内容 - 注意第二个Aggregations()函数是Filter()函数的子函数。
Dim queryResults = elasticClient.Search(Of Mail)(Function(s) s. Size(0). Aggregations(Function(a) a. Filter("AutoComplete", Function(f) f. Filter(Function(ff) ff. Match(Function(m) m. Field("claimData.claimOwner"). Query("dav") ) ). Aggregations(Function(aa) a. Terms("Suggestions", Function(t) t. Field("claimData.claimOwner.raw") ) ) ) ) )
但是Nest生成的查询看起来像:
POST /workitems_v2/mail/_search { "size" : 0, "aggs" : { "Suggestions" : { "terms" : { "field" : "claimData.claimOwner.raw" } }, "AutoComplete" : { "filter" : { "match" : { "claimData.claimOwner" : { "query" : "dav" } } } } } }
......这不能给我我想要的东西。 如何告诉Nest“建议”聚合是第一个Filter Aggregation的一部分?
I'm trying to run the following Filter Aggregation query against ElasticSearch via Nest 2.3.2.
GET workitems_v2/mail/_search { size:0, "aggs" : { "AutoComplete" : { "filter" : { "match": { "claimData.claimOwner":"dav" } }, "aggs": { "Suggestions": { "terms": {"field":"claimData.claimOwner.raw"} } } } } }
Here's what I have in Nest (VB.Net) - note how the second Aggregations() function is a child of the Filter() function.
Dim queryResults = elasticClient.Search(Of Mail)(Function(s) s. Size(0). Aggregations(Function(a) a. Filter("AutoComplete", Function(f) f. Filter(Function(ff) ff. Match(Function(m) m. Field("claimData.claimOwner"). Query("dav") ) ). Aggregations(Function(aa) a. Terms("Suggestions", Function(t) t. Field("claimData.claimOwner.raw") ) ) ) ) )
But the query that Nest generates looks like:
POST /workitems_v2/mail/_search { "size" : 0, "aggs" : { "Suggestions" : { "terms" : { "field" : "claimData.claimOwner.raw" } }, "AutoComplete" : { "filter" : { "match" : { "claimData.claimOwner" : { "query" : "dav" } } } } } }
... which doesn't give me what I want. How do I tell Nest that the "Suggestions" aggregation is part of the first Filter Aggregation?
原文:https://stackoverflow.com/questions/37748583
最满意答案
该循环在您的一生中不可能结束。
10 ** 100
是一个非常庞大的数字。 它比宇宙中的粒子数量还要多,它比宇宙创造以来最小的时间数量还要多。 在一台不可能的快速电脑上 -3 * 10 ** 46
千年的循环才能完成。 要计算一个无限的总和,你希望计算,直到总和停止变化很大(例如,加数已经下降到某个非常小的阈值)。另外,Python 2中的
xrange
和range
仅限于平台的长整数,这意味着在32位机器上不能有高于2 ** 31的数字,在64位上不能有2 ** 63(后者仍然很大,无法在你的生命中完成),这就是为什么你在Python 2中得到一个OverflowError
原因。在Python 3中,你不会有错误,但是总结会一直持续下去。而这样一个大数的计算阶乘更慢,所以即使在32位机器上,你也没有机会超过最大值。
搜索一个计算无穷和的函数,或者自己做
>>> from __future__ import division >>> import itertools >>> from math import factorial, cos, e >>> for t in [0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1]: ... summables = ((4 ** (2 * n) * cos(2 * n * t)) / (e ** 16 * factorial(n)) ... for n in itertools.count()) ... print 0.5 * (1 + sum(itertools.takewhile(lambda x: abs(x) > 1e-80, summables))) ... 1.0 0.973104754771 0.89599816753 0.77928588758 0.65382602277 0.569532373683 0.529115621076 0.512624956755 0.505673516974 0.502777962546 0.501396442319
另外,我不承认公式,但是这应该是
(e ** 16) * factorial(n)
或e ** (16 * factorial(n))
? 我只想指出,由于另一个答案,你写了前者。That loop can't possibly end during your lifetime.
10 ** 100
is a really really enormous number. It's bigger than the number of particles in the universe, it's bigger than the number of the tiniest time periods that have passed since the creation of the universe. On an impossibly fast computer -3 * 10 ** 46
millennia for the loop to complete. To calculate an infinite sum you'd wish to calculate until the sum has stopped changing significantly (e.g. the summands have fallen under certain very small threshold).Also,
xrange
andrange
in Python 2 are limited to the platform's long integers, which means that you can't have numbers higher than 2 ** 31 on a 32 bit machine and 2 ** 63 on a 64 bit one, (the latter is still too big to ever complete in your lifetime), this is why you get anOverflowError
in Python 2. In Python 3 you'd get no error, but the summation will continue forever.And calculation factorial of such a large number is even slower, so you don't have a chance to ever exceed the maximum even on a 32 bit machine.
Search for a function for calculating infinite sums, or do it yourself
>>> from __future__ import division >>> import itertools >>> from math import factorial, cos, e >>> for t in [0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1]: ... summables = ((4 ** (2 * n) * cos(2 * n * t)) / (e ** 16 * factorial(n)) ... for n in itertools.count()) ... print 0.5 * (1 + sum(itertools.takewhile(lambda x: abs(x) > 1e-80, summables))) ... 1.0 0.973104754771 0.89599816753 0.77928588758 0.65382602277 0.569532373683 0.529115621076 0.512624956755 0.505673516974 0.502777962546 0.501396442319
Also, I do not recognize the formula, but is this supposed to be
(e ** 16) * factorial(n)
ore ** (16 * factorial(n))
? I just want to point out that you've written the former because of the other answer.
相关问答
更多-
sum() python[2022-05-21]
因为你把一个等号写成了== def digit_sum(n): a=0 for i in str(n): a=i+a #此处的==改成= return a 第二个除了相同错误外,i未定义,条件应为while n>0: -
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
你不能用numpy.ndarray分割numpy.float64 。 这是有问题的代码: return 0.5*(1 + sum( (a**(2*n)*cos(2*sqrt(1 + n)*t))/(e**a**2*factorial(n)) You can't divide a numpy.ndarray by a numpy.float64. This is the problematic code: return 0.5*(1 + sum( (a**(2*n)*cos(2*sqrt(1 + n)*t) ...
-
python中的sum函数(sum function in python)[2023-11-04]
当你这样做 from SomeModule import * 你确实凌驾于内置和函数。 这会将numpy命名空间中的所有内容导入默认命名空间。 您可能想要做的是: import numpy as np 然后,您可以将numpy点函数作为np.dot访问。 通过这种方式,如果它们定义了相同名称的函数,则可以使命名空间不会相互踩踏。 另一个选择,如果你只想要点功能就是这样做: from numpy import dot 然后点函数是numpy中唯一可用的函数。 这些是使用其他模块时采用的两种主要方法。 导 ... -
Sum()在python中(Sum() in python)[2024-01-28]
sum((m - r + 1) * (n - r + 1) for r in xrange(1,n+1)) 整数之间没有隐式的乘法,所以你需要* 。 f(x) for x in xes是列表理解的一般格式,您希望x遍历xes每个元素,并返回值f(x) 。 sum((m - r + 1) * (n - r + 1) for r in xrange(1,n+1)) There's no implicit multiplication between integers, so you need the *. ... -
在python中绘制一笔总和(Plotting a sum in python)[2021-11-22]
该循环在您的一生中不可能结束。 10 ** 100是一个非常庞大的数字。 它比宇宙中的粒子数量还要多,它比宇宙创造以来最小的时间数量还要多。 在一台不可能的快速电脑上 - 3 * 10 ** 46千年的循环才能完成。 要计算一个无限的总和,你希望计算,直到总和停止变化很大(例如,加数已经下降到某个非常小的阈值)。 另外,Python 2中的xrange和range仅限于平台的长整数,这意味着在32位机器上不能有高于2 ** 31的数字,在64位上不能有2 ** 63(后者仍然很大,无法在你的生命中完成),这 ... -
Python中的双重总和(Double sum in Python)[2023-01-23]
如果要返回函数f(i,j) - > X [i] .W [j]: def func(X,W): def f(i,j): return np.dot(X[i],W[j]) return f 将工作。 编辑: 在编辑中命名为Func的VALUE由sum([np.dot(x,w) for x in X for w in W])计算sum([np.dot(x,w) for x in X for w in W])或者更高效, np.einsum('ij,kj->',X,W) 。 如果你想返回返回Fun ... -
Python中嵌套列表的总和(sum of nested list in Python)[2023-07-01]
您需要使用isinstance来检查元素是否为列表。 此外,你可能想遍历实际的列表,使事情变得更简单。 def nested_sum(L): total = 0 # don't use `sum` as a variable name for i in L: if isinstance(i, list): # checks if `i` is a list total += nested_sum(i) else: ... -
python中的内置sum函数(In-built sum function in python)[2022-04-22]
您不需要通过索引访问元素。 如果列表不为空且所有元素的类型相同,则可以按如下方式编写代码: >>> def sum_elements(l): ... s = l[0] ... for element in l[1:]: ... s += element ... return s ... >>> sum_elements([1, 2, 3]) 6 >>> sum_elements(['hello', 'world']) 'helloworld' You don't ...