2017-09-13 39 views
1

我想根据按源分组的最大时间戳获取价格。Solr方面搜索 - 获取基于最大值和分组的价值

我现在拥有的Solr查询会为每个源拉取最大时间戳。我如何修改这个查询来拉取与最大时间戳相关的相应价格?

http://localhost:6500/solr/listings/select?q=desc_t:"Watch"&indent=on&rows=0&indent=true&wt=json&json.facet= 
{ 
    prices: { 
     type: terms, 
     field: source_s, 
     facet: { 
      max_ingestdate: "max(timestamp_dt)"     
       } 

      } 
     } 

这个返回:

"facets":{ 
    "count":141211, 
    "prices":{ 
     "buckets":[{ 
      "val":"a1", 
      "count":71466, 
      "max_ingestdate":1.505277283278E12}, 
     { 
      "val":"a2", 
      "count":52415, 
      "max_ingestdate":1.501872553356E12}, 
     { 
      "val":"a3", 
      "count":7866, 
      "max_ingestdate":1.504798294686E12},.... 

我也希望corressponding价格因此最终结果应该是:

"facets":{ 
"count":141211, 
"prices":{ 
    "buckets":[{ 
     "val":"a1", 
     "count":71466, 
     "max_ingestdate":1.505277283278E12, 
     "price": 1334}, 
    { 
     "val":"a2", 
     "count":52415, 
     "max_ingestdate":1.501872553356E12, 
     "price": 1234}, 
    { 
     "val":"a3", 
     "count":7866, 
     "max_ingestdate":1.504798294686E12 
     "price": 1342},... 

回答

1

我不知道它是可以随便抓一个文件在json方面,但如果你只是想使用最新的价格,这里可以使用一个半黑客。从本质上讲,您可以按照源代码进行构建,然后在该源代码构面中使用一系列短时间窗口中的价格查询构面。

Solr的调用看起来像:

http://localhost:65000/solr/listings/select?q=description_t:"Watch"&indent=on&rows=0&indent=true&wt=json&json.facet= 
    { 
     prices: { 
      type: terms, 
      field: source_s, 
      facet: { 
       max_ingestdate: "max(timestamp_dt)", 
       max_price: "max(price_d)", 
       price_1: { 
        type: query, 
        q: "timestamp_dt:[NOW-1DAY TO NOW]", 
        facet: { 
         avg_price_1: "avg(price_d)" 
        } 
       }, 
       price_2: { 
        type: query, 
        q: "timestamp_dt:[NOW-7DAY TO NOW-1DAY]", 
        facet: { 
         avg_price_2: "avg(price_d)" 
        } 
       }, 
       price_3: { 
        type: query, 
        q: "timestamp_dt:[NOW-14DAY TO NOW-7DAY]", 
        facet: { 
         avg_price_3: "avg(price_d)" 
        } 
       } 
      } 

     } 
    } 
+0

是。这里看起来像最佳的解决方案为止。 – Gayatri

+0

我想知道是否有其他方法? – Gayatri