在elasticsearch中具有多个存储桶路径的存储桶选择器

时间:2017-04-13 09:38:29

标签: elasticsearch elasticsearch-5 elasticsearch-query

我对弹性搜索很新。基本上,我试图在他们的parentId上加入两个文件,并且在一个额外的条件下。

所以,如果我在一个sql世界,这将是这样的。

select d1.page_view_ts,
       d2.tx_ts,
       d1.parent_id
from (select parent_id,
    min(page_view_timestamp) as page_view_ts
    from doc1
    group by parent_id) as d1
join (select parent_id,
    max(transaction_timestamp) as tx_ts
    from doc2
    group by parent_id) as d2
on d1.parent_id == d2.parent_id where d1.page_view_ts < d2.tx_ts

这就是我尝试使用elasticsearch

{
  "aggs": {
    "sessionKeyBucket": {
      "terms": { "field": "sessionKey", "size": 100 },
      "aggs": {
        "pageViewChildren": {
          "children": { "type": "pageviews" },
          "aggs": {
              "minPageViewTs": {
              "min": { "field": "pageViewTime" }
              }
            }
          },
        "transactionChildren": {
            "children": { "type": "transactions" },
            "aggs": {
              "maxTransactionTs": {
              "max": {"field": "transactionTime"}
              }
            }
        },
        "bucket_selector": {
            "buckets_path": {
                "pageViewTs": "minPageViewTs", 
                "transactionTs": "maxTransactionTs"
            },
            "script": "params.pageViewTs < params.transactionTs"
        }
      }
    }
  }
}

ElasticSearch中的映射看起来像这样

"mappings": {
    "sessions": {
        "_all": {
          "enabled": false
        },
        ...

    "transactions": {
        "_parent": {
            "type": "sessions"
        },
        ...

     "pageviews": {
        _parent": {
            type": "sessions"
        },
        ...
}

因此,由于某些原因这不起作用。 如果你们可以向我展示如何在几个存储桶路径上使用存储桶选择器的示例,那将是非常棒的。

由于

0 个答案:

没有答案