简体   繁体   English

方面中的弹性搜索过滤

[英]Elastic Search filtering in facets

I want to simulate a parent child relation in elastic search and perform some analytics work over it. 我想在弹性搜索中模拟父子关系并对其执行一些分析工作。 My use case is something like this 我的用例是这样的

I have a shop owner like this 我有这样的店主

"_source": {
               "shopId": 5,
               "distributorId": 4,
               "stateId": 1,
               "partnerId": 2,
            }

and now have child records (for each day) like this: 现在有这样的子记录(每天):

"_source": {
                   "shopId": 5,
                   "date" : 2013-11-13,
                   "transactions": 150,
                   "amount": 1980,
                }

The parent is a record per store, while the child is the transactions each store does for day. 父级是每个商店的记录,而子级是每个商店一天的交易。 Now I want to do some complex query like 现在我想做一些复杂的查询

Find out total transaction for each day for the last 30 days where distributor is 5 找出最近30天每天的总交易额,其中分销商为5

POST /newdb/shopsDaily/_search
{
   "query": {
      "match_all": {}
   },
   "filter": {
      "has_parent": {
         "type": "shop",
         "query": {
            "match": {
               "distributorId": "5"
            }
         }
      }
   },
   "facets": {
      "date": {
         "histogram": {
            "key_field": "date",
            "value_field": "transactions",
            "interval": 100
         }
      }
   }
}

But the result I get do not take the filtering into account which I applied. 但是我得到的结果没有考虑我应用的过滤。

So I changed the query to this: 所以我将查询更改为:

POST /newdb/shopDaily/_search
{

      "query": {"filtered": {
         "query": {"match_all": {}},
         "filter": { "has_parent": {
            "type": "shop",
            "query": {"match": {
               "distributorId": "13"
            }}
         }}
      }}, 
      "facets": {
         "date": {
            "histogram": {
               "key_field": "date",
               "value_field": "transactions", 
               "interval": 100
            }
         }

      }
}

And then the final histogram facet took filtering into count. 然后,最终的直方图构面将过滤纳入计数。

So, when I browsed though I found out this is due to using filtered (which can only be used inside query clause and not outside like filter ) rather than filter , but it also mentioned that to have fast search you should use filter . 所以,当我浏览但我发现这是由于使用filtered (只能查询子句中使用,而不是像外界filter ),而不是filter ,但它也提到,有快速搜索,你应该使用filter Will searching as I did in second step (when I used filtered instead of filter ) effect the performance of elastic search? 将搜索,因为我在第二个步骤做了(当我用filtered的,而不是filter )实现弹性搜索的性能? If so, how can I make my facets honor filters and not effect the performance? 如果是这样,如何使我的构面成为荣誉筛选器而不影响性能?

Thanks for you time 谢谢你的时间

filters in Filtered query (filters in query clause) are cached, hence faster. 缓存了过滤查询中的过滤器(查询子句中的过滤器),因此速度更快。 These type of filters affect both search result and facet counts. 这些类型的过滤器会影响搜索结果和构面计数。 Filters outside the query clause are not considered during facet calculations. 构面计算期间不考虑查询子句外部的过滤器。 They are considered only for search results. 仅将它们视为搜索结果。 Facet is calculated only on the query clause. 构面仅在查询子句上计算。 If you want filtered facets then you need to set filters to each of the facet clauses. 如果要过滤构面,则需要为每个构面子句设置过滤器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM