2

我的文件是:

Iwp::1::Porcentaje::Period::1
{
  "id": null,
  "period": 1,
  "type": "IwpCumulative",
  "category": "Porcentaje",
  "sumEarn": 0,
  "sumActual": 0.2248520710059172,
  "sumForecast": 0,
  "sumPlanned": 0,
  "sumValue": 0,
  "parent": "Iwp::1"
}

Iwp::1
{
  "name": "Iwp 1",
  "description": "Iwp 1 Description",
  "manyPeriods": 50,
  "type": "Iwp",
  "countCC": 0,
  "costCode": [
    "CostCode::3",
    "CostCode::4"
  ],
  "iwpCumulatives": [
    "Iwp::1::Porcentaje::Period::1",
     .......
    "Iwp::1::Porcentaje::Period::50",
    "Iwp::1::Qty::Period::1",
........
    "Iwp::1::Qty::Period::50",
  ]
}

我如何在 ElasticSearch 上进行此查询?

N1QL:

select 
t.category,
t.period,
sum(t.sumActual) 
from 
default as q 
inner join default as p on keys q.parent 
inner join default as t on keys p.iwpCumulatives 
where
q.type = 'IwpCumulative' 
and q.period = 50
and q.sumActual > 0 
and q.category = 'Porcentaje' 
group by t.category,t.period
order by t.period,t.category;

我在 ElasticSearch 有以下查询:

{
    "query":{
    "filtered":{
           "query":{
               "bool":{
                    "must":[
                        {"term":{"period":"5"}},
                        {"term":{"type":"iwpcumulative"}},
                        {"range":{"sumActual":{"gt":"0"}}},
                        {"term":{"category":"porcentaje"}}
                        ]
                }
            }
    }
    }
}

和这个:

{
   "size":0,
   "aggs":{
      "group_by_state":{
         "terms":{
            "field":"category"
         },
         "aggs":{
            "costars":{
               "terms":{
                  "field":"period"
               },
               "aggs":{
                  "Suma":{
                     "sum":{
                        "field":"earn"
                     }
                  }
               }
            }
         }
      }
   }
}

现在,我需要将第一个结果与他们的 Id 一起使用,因此我将在第二个查询中使用。

提前致谢。

4

1 回答 1

1

因为您只使用一个表导致选择术语(半连接),所以您可以使用 seren-join 插件进行弹性搜索:看看这个:

SIRen 插件为 Elasticsearch 添加关系连接功能

于 2016-08-24T13:01:23.490 回答