- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 Elasticsearch 来存储我的生物数据。
我尝试使用过滤后的 aggs 进行查询,但返回的数据不是我想要的。
问题来自这样一个事实,即我为每个样本都有一个“d_”属性,它是一个数组。我只需要对该数组的某些元素进行聚合,但我无法过滤它们。
//我手动编辑数据以使其更易于理解,因此可能存在一些拼写错误
我的数据示例:
[ {
"_index": "botanique",
"_type": "specimens",
"_id": "227CB8A3E2834AAEB50B1ECF6B672180",
"_score": 1,
"_source": {
....
"d_": [
{ // -------------- dont want this
"taxonid": "BB7C33A3126648D095BEDDABB0BD2758",
"scientificname": "Lastreopsis effusa",
"scientificnameauthorship": "(Sw.) Tindale"
},
{ // -------------- want this
"taxonid": "704FC303D7F74C02912D0FEB5C6FC55D",
"scientificname": "Parapolystichum effusum",
"scientificnameauthorship": "(sw.) copel."
}
]
}
} , {
"_index": "botanique",
"_type": "specimens",
"_id": "11A22DE8E4AD45BBAC7783E508079DCD",
"_score": 1,
"_source": {
....
"d_": [
{ // -------------- want this
"taxonid": "A94D243348DF4CAD926B6C3965D948A3",
"scientificname": "Parapolystichum effusum",
"scientificnameauthorship": "(Sw.) Ching",
} ,
{ // -------------- dont want this
"taxonid": "B01A89AA961A46F2984722C311DC2BDD",
"scientificname": "Lastreopsis effusa",
"scientificnameauthorship": "(willd. ex schkuhr) proctor"
}
]
}
},{
"_index": "botanique",
"_type": "specimens",
"_id": "1647F5E23D304EFAAB9D3E3BE80FD3CE",
"_score": 1,
"_source": {
...
"d_": [
{ // -------------- want this
"taxonid": "D70C4478D2B0437AA940994E98D696C5",
"scientificname": "Parapolystichum effusum",
"scientificnameauthorship": "(Sw.) Ching"
} ,
{ // -------------- dont want this
"taxonid": "011E5DA526FC4098953DBD1F9E5F4424",
"scientificname": "Lastreopsis effusa",
"scientificnameauthorship": "(Sw.) Tindale",
}
]
}
}
]
{
"_source": ["d_" ],
"size": 3,
"query": {
"filtered": {"filter": {"bool": {"must": [{"term": {
"d_.scientificname": "parapolystichum effusum"
}}] } }}
},
"aggs": {
"scientificname": {
"terms": {
"field": "d_.scientificname",
"size": 1,
"include": {
"pattern": "parapolystichum effusum",
"flags": "CANON_EQ|CASE_INSENSITIVE"
}
},
"aggs": {
"scientificnameauthorship": {
"terms": {
"field": "d_.scientificnameauthorship",
"size": 10
}
}
}
}
}
}
{
"aggregations": {
"scientificname": {
"buckets": [{
"key": "parapolystichum effusum",
"doc_count": 269,
"scientificnameauthorship": {
"buckets": [
{ // ------ want this
"key": "(sw.) ching",
"doc_count": 269
} ,
{ // ------ want this
"key": "(sw.) copel.",
"doc_count": 34
} ,
{ // ------ dont want this
"key": "(sw.) tindale",
"doc_count": 262
} ,
{ // ------ dont want this
"key": "(willd. ex schkuhr) proctor",
"doc_count": 7
} ,
{ // ------ dont want this
"key": "fée",
"doc_count": 2
}
]
}
}]
}
}
}
{
"hits": {
"total": 269,
"max_score": 1,
"hits": [
{
"_index": "botanique",
"_type": "specimens",
"_id": "1647F5E23D304EFAAB9D3E3BE80FD3CE",
"_score": 1,
"_source": {
...
"d_": [{ // -------------- want this
"taxonid": "D70C4478D2B0437AA940994E98D696C5",
"scientificname": "Parapolystichum effusum",
"scientificnameauthorship": "(Sw.) Ching"
}]
}
}
}
}
{
"hits": {
"total": 269,
"max_score": 1,
"hits": [
{
"_index": "botanique",
"_type": "specimens",
"_id": "1647F5E23D304EFAAB9D3E3BE80FD3CE",
"_score": 1,
"_source": {
...
"d_": [
{ // -------------- want this
"taxonid": "D70C4478D2B0437AA940994E98D696C5",
"scientificname": "Parapolystichum effusum",
"scientificnameauthorship": "(Sw.) Ching"
} ,
{ // -------------- dont want this
"taxonid": "011E5DA526FC4098953DBD1F9E5F4424",
"scientificname": "Lastreopsis effusa",
"scientificnameauthorship": "(Sw.) Tindale",
}
]
}
}
}
}
{
"query": {
"filtered": {"filter": {"bool": {"must": [{"term": {
"d_.scientificname": "parapolystichum effusum"
}}] } }}
},
"aggs" : {
"scientificname" : {
"filter" : {"term": {
"d_.scientificname": "parapolystichum effusum"
}},
"aggs": {
"scientificnameauthorship": {
"terms": {
"field": "d_.scientificnameauthorship",
"size": 10
}
}
}
}
}
}
最佳答案
您可以使用嵌套的聚合器作为父聚合器。然后在父聚合器中创建一个新的过滤聚合器来过滤数组(列表数据)并附加另一个子聚合器以进行术语聚合。
https://www.elastic.co/guide/en/elasticsearch/reference/1.4/search-aggregations-bucket-nested-aggregation.html
示例查询
"filteredaggs" : {
"nested" : {
"path" : "D_"
},
"aggs" : {
"maxdays" : {
"filter" : {
"terms" : {
"scientificname" : ["xyz", "pqr"]
}
},
"aggs" : {
"myfinalaggregator" : {
"terms" : {
"field" : "scientificnameauthorship"
}
}
}
}
}
}
关于elasticsearch 使用 aggs 过滤数组数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33626289/
我有两种方法来汇总数据。 首先,我过滤mysql数据并进行汇总 其次,i aggs将数据过滤为aggs。 如下: 我发现了不同的结果,我不知道为什么。 有人可以解释吗? 最佳答案 从Docs By d
在一个具体问题上,假设我有一个 DataFrame DF word tag count 0 a S 30 1 the S 20 2 a T
我正在使用Python进行数据分析,但我遇到了部分CH的问题。9(数据聚合和分组操作)部分,介绍“使用函数分组”。。具体地说,如果我使用GroupBy对象方法或Numpy定义的函数,一切都会正常工作。
接听this question原来 df.groupby(...).agg(set) 和 df.groupby(...).agg(lambda x: set(x)) 正在产生不同的结果。 数据: df
如何在这样的字符串列中执行最大值? dataframe = pandas.DataFrame.from_dict( { "DEP
我有一个查询,用于查询给定日期时间窗口(即2017-02-17T15:00:00.000和2017-02-17T16:00:00.000之间)中的条目数。执行此查询时,我得到的结果不正确(最好说结果是
我正在尝试进行一些聚合查询并遇到一些问题。 GET /my_index/_search { "size" : 0, "aggs":{ "group_by":{ "terms": {
对于pandas agg,有没有办法根据数据类型指定聚合函数?例如,对象类型的所有列都获得“第一”,所有 float 获得“平均值”,等等?以避免必须输入所有列及其各自的聚合函数。 示例数据: imp
这是我当前的代码: pipe_exec_df_final_grouped = pipe_exec_df_final.groupBy("application_id").agg(collect_list
我有一个简单的 dataframe (df),如下所示: index Job Person 1 j1 Cathy 2 j2 Mark 3 j3 Cathy 4
我正在尝试对术语(count_bucket)进行AVG计数,但是出现错误: "buckets_path must reference either a number value or a single
我正在执行弹性查询并使用 REST 调用读取 java 代码中的响应。 当我阅读响应时,字段的顺序 - 200、204、4xx、5xx 不会按照响应中的顺序返回。 在下面找到示例请求 GET appl
我希望对文档下的属性值进行 Max 聚合,该属性是复杂对象(键和值)的列表。这是我的数据: [{ "id" : "1", "listItems" : [
我使用 Elasticsearch 来存储我的生物数据。 我尝试使用过滤后的 aggs 进行查询,但返回的数据不是我想要的。 问题来自这样一个事实,即我为每个样本都有一个“d_”属性,它是一个数组。我
当我尝试运行此查询时,elasticsearch无法回答,并且发生大量缓存逐出(与字段缓存有关)。 我不想在此查询中缓存任何字段,因为这是一个分析查询,我每天只运行一次。有什么办法可以在不使用字段缓存
我想将 DataFrame.agg 的输出转换为一个系列,其中索引是列名称和 agg 函数名称的组合。 看我有 In [132]: df = pd.DataFrame({ ...:
我想根据索引的第二级对具有多重索引的数据帧应用不同的函数。 例如,对于数据框: In [4]: df = pd.DataFrame({'a': [1,2,6,7],'b': [7,1,4,5]}, i
假设我有这样的代码: meanData = all_data.groupby(['Id'])[features].agg('mean') 这按'Id' 值对数据进行分组,选择所需的特征,并通过计算的'
下面是我的数据框的一个小样本,它有 25000 奇数行长: In [58]: df Out[58]: Send_Agent Send_Amount 0 ADR000264 361
假设我有一个 pandas dataFrame (data_stores) 类似于以下内容: store| item1 | item2 | item3 ------------------------
我是一名优秀的程序员,十分优秀!