Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
可以在服务器上进一步过滤使用sum函数的SOLR分面结果吗_Solr - Fatal编程技术网

可以在服务器上进一步过滤使用sum函数的SOLR分面结果吗

可以在服务器上进一步过滤使用sum函数的SOLR分面结果吗,solr,Solr,在SOLR版本6.0.0中,在将响应返回到客户端之前,是否可以进一步过滤分面结果?我的用例使用facet“sum”函数来计算每个客户的总存款。到目前为止还不错 我想过滤facet响应中返回的行,只显示那些存款超过某个阈值的客户。我似乎找不到一个办法来做那件事。可能吗 我试图避免在响应从SOLR服务器返回后处理它。我想知道是否有可能在服务器端实现这一点。我尝试这样做的原因是在服务器端,因为数据集可能非常大。如果我在客户端这样做,我可能需要使用“limit”和“offset”参数进行多方面的搜索,以

在SOLR版本6.0.0中,在将响应返回到客户端之前,是否可以进一步过滤分面结果?我的用例使用facet“sum”函数来计算每个客户的总存款。到目前为止还不错

我想过滤facet响应中返回的行,只显示那些存款超过某个阈值的客户。我似乎找不到一个办法来做那件事。可能吗

我试图避免在响应从SOLR服务器返回后处理它。我想知道是否有可能在服务器端实现这一点。我尝试这样做的原因是在服务器端,因为数据集可能非常大。如果我在客户端这样做,我可能需要使用“limit”和“offset”参数进行多方面的搜索,以找到阈值的位置。一旦找到,继续使用用例

参考文献:

下面是我设置环境的步骤

  • 使用以下数据创建了名为entry.csv的csv文件

    id,name_s,date_dt,flow_s,amount_f
    1,John,2016-01-01T00:00:00Z,Deposit,10
    2,Mary,2016-01-15T00:00:00Z,Deposit,20
    3,Peter,2016-01-19T00:00:00Z,Deposit,30
    4,John,2016-01-20T00:00:00Z,Deposit,40
    5,Mary,2016-01-22T00:00:00Z,Deposit,50
    6,Mary,2016-01-23T00:00:00Z,Deposit,60
    
  • 启动SOLR服务器

    $ bin/solr start
    
  • 创建一个名为simple的新核心

    $ bin/solr create -c simple
    
  • 导入数据

    $ bin/post -c simple ~/entry.csv
    
  • 查询数据以验证导入是否成功

    $ curl -s http://localhost:8983/solr/simple/select?indent=on&q=*:*&wt=json
    {
      "responseHeader":{
        "status":0,
        "QTime":0,
        "params":{
          "q":"*:*",
          "indent":"on",
          "wt":"json"}},
      "response":{"numFound":6,"start":0,"docs":[
          {
            "id":"1",
            "name_s":"John",
            "date_dt":"2016-01-01T00:00:00Z",
            "flow_s":"Deposit",
            "amount_f":10.0,
            "_version_":1532465926194069504},
          {
            "id":"2",
            "name_s":"Mary",
            "date_dt":"2016-01-15T00:00:00Z",
            "flow_s":"Deposit",
            "amount_f":20.0,
            "_version_":1532465926248595456},
          {
            "id":"3",
            "name_s":"Peter",
            "date_dt":"2016-01-19T00:00:00Z",
            "flow_s":"Deposit",
            "amount_f":30.0,
            "_version_":1532465926250692608},
          {
            "id":"4",
            "name_s":"John",
            "date_dt":"2016-01-20T00:00:00Z",
            "flow_s":"Deposit",
            "amount_f":40.0,
            "_version_":1532465926252789760},
          {
            "id":"5",
            "name_s":"Mary",
            "date_dt":"2016-01-22T00:00:00Z",
            "flow_s":"Deposit",
            "amount_f":50.0,
            "_version_":1532465926253838336},
          {
    me_s":"Mary",
            "date_dt":"2016-01-23T00:00:00Z",
            "flow_s":"Deposit",
            "amount_f":60.0,
            "_version_":1532465926255935488}]
      }}
    
  • 使用显示每个客户的总存款金额的方面查询数据

    $ curl -s http://localhost:8983/solr/simple/select -d 'q=*:*&rows=0&
    json.facet={
      customers:{
       type:terms,
       field:name_s,
       sort:{gross:desc},
       facet:{
         gross:"sum(amount_f)"
       }
      }
    }
    
    <?xml version="1.0" encoding="UTF-8"?>
    <response>
      <lst name="responseHeader">
        <int name="status">0</int>
        <int name="QTime">1</int>
        <lst name="params">
          <str name="q">*:*</str>
          <str name="json.facet">{   customers:{    type:terms,    field:name_s,    sort:{gross:desc},    facet:{      gross:"sum(amount_
          <str name="rows">0</str>
        </lst>
      </lst>
      <result name="response" numFound="6" start="0"/>
      <lst name="facets">
        <int name="count">6</int>
        <lst name="customers">
          <arr name="buckets">
            <lst>
              <str name="val">Mary</str>
              <int name="count">3</int>
              <double name="gross">130.0</double>
            </lst>
            <lst>
              <str name="val">John</str>
              <int name="count">2</int>
              <double name="gross">50.0</double>
            </lst>
            <lst>
              <str name="val">Peter</str>
              <int name="count">1</int>
              <double name="gross">30.0</double>
            </lst>
          </arr>
        </lst>
      </lst>
    </response>
    
    $curl-shttp://localhost:8983/solr/simple/select -d'q=*:*&行=0&
    json.facet={
    顾客:{
    类型:术语,
    字段:name_s,
    排序:{gross:desc},
    方面:{
    总额:“金额”
    }
    }
    }
    0
    1.
    *:*
    {customers:{type:terms,field:name_s,sort:{gross:desc},facet:{gross:sum(amount_
    0
    6.
    玛丽
    3.
    130
    约翰
    2.
    50
    彼得
    1.
    30
    
  • 我想达到的目标


  • 我只想筛选那些存款超过100美元的客户。这意味着在响应中,我只想看到总存款为130美元的Mary。我不想看到John或Peter回来。

    在Apache SOLR cloud的6.3.0版中,有一个内置的“/sql”“处理程序。有关处理程序的详细信息,请参见下面URL处的apache wiki页面

    要获得问题#7的结果,可以提交以下查询,如果名称和合计金额超过100,则结果将仅显示名称和合计金额

    stmt=SELECT name_s, sum(amount_f) as total
    FROM simple
    GROUP BY name_s
    HAVING total > 100
    ORDER BY total desc
    
    在我的本地环境中,SOLR cloud托管在ip 10.0.0.40和端口8983上,我创建了一个集合名称“simple”

    curl --data-urlencode 'stmt=SELECT name_s, sum(amount_f) as total FROM simple GROUP BY name_s HAVING total>100 ORDER BY total desc' http://10.0.0.40:8983/solr/simple/sql
    
    
    {"result-set":{"docs":[
    {"name_s":"Mary","total":130.0},
    {"EOF":true,"RESPONSE_TIME":7}]}}