【问题标题】:Faceting with Rubberband用橡皮筋刻面
【发布时间】:2013-05-15 10:23:21
【问题描述】:

我正在使用 RubberBand gem 在 Ruby-on-Rails 2.3 应用程序中实现 ElasticSearch。我正在尝试返回方面,但似乎找不到可用于此目的的方法。我查看了documentation and source

有谁知道橡皮筋可以吗?

【问题讨论】:

    标签: ruby-on-rails elasticsearch facets rubber-band


    【解决方案1】:

    这个问题可能有你要找的东西:

    https://github.com/grantr/rubberband/issues/4

    q = {
      "query"=> {
        "filtered"=> {
          "query"=> { 
            "match_all"=> {}
          },
          "filter"=> {
            "term"=> {
              "client_id"=> "717",
              "product_id"=> "1"
            }
          }
        }
      },
      "facets"=> {
        "shipped_to_state_counts"=> {
          "terms"=> {
            "field"=> "state",
            "size"=> "500"
          }
        }
      }
    }
    

    编辑:(更简单的查询,lucene 语法)

    注意:根据 elasticsearch 文档,这些不是相同的查询:

    要记住一个重要的区别。搜索时 queries 限制返回的文档和构面计数,搜索 filters 仅限制返回的文档——但不限制构面计数。

    q = {
      "query"=> {
        "query_string"=> {
          "query"=> "client_id:717 AND product_id:1"
        }
      },
      "facets"=> {
        "shipped_to_state_counts"=> {
          "terms"=> {
            "field"=> "state",
            "size"=> "500"
          }
        }
      }
    }
    

    结束编辑

    results = client.search(q)
    facets = results.facets
    
    =>
    {
      "shipped_to_state_counts"=> {
        "_type"=> "terms",
        "missing"=> 0,
        "total"=> 1873274,
        "other"=> 0,
        "terms"=> [
          {
            "term"=> "MO",
            "count"=> 187327
          },
          {
            "term"=> "FL",
            "count"=> 17327
          }
        ]
      }
    } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-05
      • 1970-01-01
      • 2010-09-30
      • 2013-12-24
      • 2014-06-15
      • 2011-01-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多