如何使用Solr查询而不是MySQL多字段分组

时间:2019-05-02 07:14:24

标签: solr solr-query-syntax

需要使用Solr查询搜索来代替MySQL语句,但是效果不好。

当前的MYSQL表

表1-文件

字段:DOCUMENT_ID,USER_ID,DEVICE_NAME,JOB_TYPE,PAGE_COUNT

表2-DOC_GROUP

字段:DOCUMENT_ID,GROUP_ID

MySQL原始语句

SELECT DATE(CREATED_DATE) AS DateOnly, USER_ID, DEVICE_NAME, JOB_TYPE, GROUP_ID, SUM(PAGE_COUNT) AS COUNTER,COUNT(T1.DOCUMENT_ID) AS DOC_COUNT 
FROM DOCUMENTS T1 inner join DOC_GROUP T2
WHERE CREATED_DATE >='2011-01-01 00:00:00' and CREATED_DATE <='2019-12-31 00:00:00' 
AND USER_ID='40001'
AND DEVICE_NAME='DEVICE_A'
AND T2.GROUP='GROUP_A'
GROUP BY DateOnly, USER_ID, DEVICE_NAME, JOB_TYPE, T2.GROUP_ID

最后,尝试按以下方法进行Solr查询,但仍无法返回与MySQL返回的数据相同的结果:

http://127.0.0.1:8983/solr/UDSDT/select?q=(CREATEDDATE:[2019-01-01T00:00:00Z TO 2019-12-31T23:59:59Z] AND DEVICE_NAME:("DEVICE_A") AND (GROUP_ID:("GROUP_A")))&fl=CREATEDDATE,DEVICE_NAME, JOB_TYPE,USER_ID,PAGE_COUNT&sort=CREATEDDATE+asc&start=0&rows=60&wt=xml&indent=true&group=true&group.field=USER_ID&group.main=true&stats=true&stats.facet=DEVICE_NAME&JOB_TYPE&USER_ID&stats.field=PAGE_COUNT

Solr的预期结果包括以下数据,并且可以分组为

Current MySQL results field sample

非常感谢。

0 个答案:

没有答案