首页 \ 问答 \ .Net Nest中的ElasticSearch过滤器聚合(ElasticSearch Filter Aggregation in .Net Nest)

.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
更新时间:2023-06-02 21:06

最满意答案

该循环在您的一生中不可能结束。 10 ** 100是一个非常庞大的数字。 它比宇宙中的粒子数量还要多,它比宇宙创造以来最小的时间数量还要多。 在一台不可能的快速电脑上 - 3 * 10 ** 46千年的循环才能完成。 要计算一个无限的总和,你希望计算,直到总和停止变化很大(例如,加数已经下降到某个非常小的阈值)。

另外,Python 2中的xrangerange仅限于平台的长整数,这意味着在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 and range 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 an OverflowError 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) or e ** (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:
  • 你不能用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) ...
  • 当你这样做 from SomeModule import * 你确实凌驾于内置和函数。 这会将numpy命名空间中的所有内容导入默认命名空间。 您可能想要做的是: import numpy as np 然后,您可以将numpy点函数作为np.dot访问。 通过这种方式,如果它们定义了相同名称的函数,则可以使命名空间不会相互踩踏。 另一个选择,如果你只想要点功能就是这样做: from numpy import dot 然后点函数是numpy中唯一可用的函数。 这些是使用其他模块时采用的两种主要方法。 导 ...
  • 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 *. ...
  • 该循环在您的一生中不可能结束。 10 ** 100是一个非常庞大的数字。 它比宇宙中的粒子数量还要多,它比宇宙创造以来最小的时间数量还要多。 在一台不可能的快速电脑上 - 3 * 10 ** 46千年的循环才能完成。 要计算一个无限的总和,你希望计算,直到总和停止变化很大(例如,加数已经下降到某个非常小的阈值)。 另外,Python 2中的xrange和range仅限于平台的长整数,这意味着在32位机器上不能有高于2 ** 31的数字,在64位上不能有2 ** 63(后者仍然很大,无法在你的生命中完成),这 ...
  • 如果要返回函数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 ...
  • 您需要使用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: ...
  • 您不需要通过索引访问元素。 如果列表不为空且所有元素的类型相同,则可以按如下方式编写代码: >>> 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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)