Note that there are some explanatory texts on larger screens.

plurals
  1. POElastic Search filtering in facets
    primarykey
    data
    text
    <p>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</p> <p>I have a shop owner like this</p> <pre><code>"_source": { "shopId": 5, "distributorId": 4, "stateId": 1, "partnerId": 2, } </code></pre> <p>and now have child records (for each day) like this:</p> <pre><code>"_source": { "shopId": 5, "date" : 2013-11-13, "transactions": 150, "amount": 1980, } </code></pre> <p>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 </p> <p>Find out total transaction for each day for the last 30 days where distributor is 5</p> <pre><code>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 } } } } </code></pre> <p>But the result I get do not take the filtering into account which I applied.</p> <p>So I changed the query to this:</p> <pre><code>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 } } } } </code></pre> <p>And then the final histogram facet took filtering into count.</p> <p>So, when I browsed though I found out this is due to using <code>filtered</code>(which can only be used inside query clause and not outside like <code>filter</code>) rather than <code>filter</code>, but it also mentioned that to have fast search you should use <code>filter</code>. Will searching as I did in second step (when I used <code>filtered</code> instead of <code>filter</code>) effect the performance of elastic search? If so, how can I make my facets honor filters and not effect the performance?</p> <p>Thanks for you time</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload