Skip to content

Commit e3bdf7a

Browse files
prepare 0.15
1 parent 351f5bd commit e3bdf7a

File tree

11 files changed

+523
-4
lines changed

11 files changed

+523
-4
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ are used for versioning (schema follows below):
1515
0.3.4 to 0.4).
1616
- All backwards incompatible changes are mentioned in this document.
1717

18+
0.15
19+
----
20+
2018-08-10
21+
22+
- Global aggregations.
23+
1824
0.14
1925
----
2026
2018-08-06

docs/changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ are used for versioning (schema follows below):
1515
0.3.4 to 0.4).
1616
- All backwards incompatible changes are mentioned in this document.
1717

18+
0.15
19+
----
20+
2018-08-10
21+
22+
- Global aggregations.
23+
1824
0.14
1925
----
2026
2018-08-06

docs/global_aggregations.rst

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
Global aggregations
2+
===================
3+
Global aggregations (facets) are regular aggregations, which are not influenced
4+
by the search query/filter. They deliver results similar to `post_filter`.
5+
6+
Sample view
7+
-----------
8+
9+
.. code-block:: python
10+
11+
from django_elasticsearch_dsl_drf.filter_backends import (
12+
CompoundSearchFilterBackend,
13+
DefaultOrderingFilterBackend,
14+
FacetedSearchFilterBackend,
15+
OrderingFilterBackend,
16+
)
17+
from django_elasticsearch_dsl_drf.viewsets import DocumentViewSet
18+
19+
from .documents import BookDocument
20+
from .serializers import BookDocumentSerializer
21+
22+
class BookCompoundSearchBackendDocumentViewSet(DocumentViewSet):
23+
24+
document = BookDocument
25+
serializer_class = BookDocumentSerializer
26+
lookup_field = 'id'
27+
28+
filter_backends = [
29+
# ...
30+
OrderingFilterBackend,
31+
DefaultOrderingFilterBackend,
32+
CompoundSearchFilterBackend,
33+
FacetedSearchFilterBackend,
34+
# ...
35+
]
36+
37+
faceted_search_fields = {
38+
'publisher': {
39+
'field': 'publisher.raw',
40+
'enabled': True,
41+
'global': True, # This makes the aggregation global
42+
},
43+
}
44+
45+
Sample request
46+
--------------
47+
48+
.. code-block:: text
49+
50+
http://localhost:8000/search/books/?facet=state_global&state=rejected
51+
52+
Generated query
53+
---------------
54+
55+
.. code-block:: javascript
56+
{
57+
"from":0,
58+
"query":{
59+
"bool":{
60+
"filter":[
61+
{
62+
"terms":{
63+
"state.raw":[
64+
"rejected"
65+
]
66+
}
67+
}
68+
]
69+
}
70+
},
71+
"size":25,
72+
"aggs":{
73+
"_filter_state_global":{
74+
"aggs":{
75+
"state_global":{
76+
"terms":{
77+
"field":"state.raw"
78+
}
79+
}
80+
},
81+
"global":{
82+
83+
}
84+
}
85+
},
86+
"sort":[
87+
"id",
88+
"title",
89+
"price"
90+
]
91+
}
92+
93+
Sample response
94+
---------------
95+
96+
.. code-block:: javascript
97+
98+
{
99+
"count": 25,
100+
"next": null,
101+
"previous": null,
102+
"facets": {
103+
"_filter_state_global": {
104+
"state_global": {
105+
"buckets": [
106+
{
107+
"doc_count": 29,
108+
"key": "not_published"
109+
},
110+
{
111+
"doc_count": 25,
112+
"key": "in_progress"
113+
},
114+
{
115+
"doc_count": 25,
116+
"key": "rejected"
117+
},
118+
{
119+
"doc_count": 21,
120+
"key": "cancelled"
121+
},
122+
{
123+
"doc_count": 17,
124+
"key": "published"
125+
}
126+
],
127+
"sum_other_doc_count": 0,
128+
"doc_count_error_upper_bound": 0
129+
},
130+
"doc_count": 117
131+
}
132+
},
133+
"results": [
134+
{
135+
"id": 1007489,
136+
"title": "Cupiditate qui nulla itaque maxime impedit.",
137+
"description": null,
138+
"summary": "Aut recusandae architecto incidunt quaerat odio .",
139+
"authors": [
140+
"Evy Vermeulen",
141+
"Tycho Weijland",
142+
"Rik Zeldenrust"
143+
],
144+
"publisher": "Overdijk Inc",
145+
"publication_date": "2014-02-28",
146+
"state": "rejected",
147+
"isbn": "978-0-15-184366-4",
148+
"price": 6.53,
149+
"pages": 82,
150+
"stock_count": 30,
151+
"tags": [
152+
"Trilogy"
153+
],
154+
"highlight": {},
155+
"null_field": null,
156+
"score": null
157+
},
158+
# ...
159+
]
160+
}

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Main features and highlights
7272
- :doc:`Multi match search filter backend <search_backends>`.
7373
- :doc:`Simple search query search filter backend <search_backends>`.
7474
- :doc:`More-like-this support (detail action) <more_like_this>`.
75+
- :doc:`Global aggregations support <global_aggregations>`.
7576

7677
Installation
7778
============

examples/simple/search_indexes/viewsets/book/base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ class BaseBookDocumentViewSet(BaseDocumentViewSet):
187187
ordering = ('id', 'title', 'price',)
188188
faceted_search_fields = {
189189
'state': 'state.raw',
190+
'state_global': {
191+
'field': 'state.raw',
192+
# 'enabled': True,
193+
'global': True,
194+
},
190195
'publisher': {
191196
'field': 'publisher.raw',
192197
'enabled': True,

global_aggregations.rst

Lines changed: 107 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Global aggregations
22
===================
3-
Global aggregations.
3+
Global aggregations (facets) are regular aggregations, which are not influenced
4+
by the search query/filter. They deliver results similar to `post_filter`.
45

56
Sample view
67
-----------
@@ -46,10 +47,114 @@ Sample request
4647

4748
.. code-block:: text
4849
49-
http://localhost:8000/search/books/?publisher=Egmont
50+
http://localhost:8000/search/books/?facet=state_global&state=rejected
51+
52+
Generated query
53+
---------------
54+
55+
.. code-block:: javascript
56+
{
57+
"from":0,
58+
"query":{
59+
"bool":{
60+
"filter":[
61+
{
62+
"terms":{
63+
"state.raw":[
64+
"rejected"
65+
]
66+
}
67+
}
68+
]
69+
}
70+
},
71+
"size":25,
72+
"aggs":{
73+
"_filter_state_global":{
74+
"aggs":{
75+
"state_global":{
76+
"terms":{
77+
"field":"state.raw"
78+
}
79+
}
80+
},
81+
"global":{
82+
83+
}
84+
}
85+
},
86+
"sort":[
87+
"id",
88+
"title",
89+
"price"
90+
]
91+
}
5092
5193
Sample response
5294
---------------
5395

5496
.. code-block:: javascript
5597
98+
{
99+
"count": 25,
100+
"next": null,
101+
"previous": null,
102+
"facets": {
103+
"_filter_state_global": {
104+
"state_global": {
105+
"buckets": [
106+
{
107+
"doc_count": 29,
108+
"key": "not_published"
109+
},
110+
{
111+
"doc_count": 25,
112+
"key": "in_progress"
113+
},
114+
{
115+
"doc_count": 25,
116+
"key": "rejected"
117+
},
118+
{
119+
"doc_count": 21,
120+
"key": "cancelled"
121+
},
122+
{
123+
"doc_count": 17,
124+
"key": "published"
125+
}
126+
],
127+
"sum_other_doc_count": 0,
128+
"doc_count_error_upper_bound": 0
129+
},
130+
"doc_count": 117
131+
}
132+
},
133+
"results": [
134+
{
135+
"id": 1007489,
136+
"title": "Cupiditate qui nulla itaque maxime impedit.",
137+
"description": null,
138+
"summary": "Aut recusandae architecto incidunt quaerat odio .",
139+
"authors": [
140+
"Evy Vermeulen",
141+
"Tycho Weijland",
142+
"Rik Zeldenrust"
143+
],
144+
"publisher": "Overdijk Inc",
145+
"publication_date": "2014-02-28",
146+
"state": "rejected",
147+
"isbn": "978-0-15-184366-4",
148+
"price": 6.53,
149+
"pages": 82,
150+
"stock_count": 30,
151+
"tags": [
152+
"Trilogy"
153+
],
154+
"highlight": {},
155+
"null_field": null,
156+
"score": null
157+
},
158+
# ...
159+
]
160+
}

scripts/prepare_docs.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ cat advanced_usage_examples.rst > docs/advanced_usage_examples.rst
99
cat nested_fields_usage_examples.rst > docs/nested_fields_usage_examples.rst
1010
cat filtering_usage_examples.rst > docs/filtering_usage_examples.rst
1111
cat more_like_this.rst > docs/more_like_this.rst
12+
cat global_aggregations.rst > docs/global_aggregations.rst

setup.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from setuptools import find_packages, setup
44

5-
version = '0.14'
5+
version = '0.15'
66

77
DOCS_TRANSFORMATIONS = (
88
(
@@ -132,6 +132,13 @@
132132
'more_like_this.html'
133133
'>`_'.format(version)
134134
),
135+
(
136+
':doc:`Global aggregations support <global_aggregations>`',
137+
'`Global aggregations support <'
138+
'http://django-elasticsearch-dsl-drf.readthedocs.io/en/{}/'
139+
'global_aggregations.html'
140+
'>`_'.format(version)
141+
),
135142
)
136143

137144
try:

src/django_elasticsearch_dsl_drf/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55
__title__ = 'django-elasticsearch-dsl-drf'
6-
__version__ = '0.14'
6+
__version__ = '0.15'
77
__author__ = 'Artur Barseghyan <[email protected]>'
88
__copyright__ = '2017-2018 Artur Barseghyan'
99
__license__ = 'GPL 2.0/LGPL 2.1'

src/django_elasticsearch_dsl_drf/tests/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .test_faceted_search import TestFacetedSearch
55
from .test_filtering_common import TestFilteringCommon
66
from .test_filtering_geo_spatial import TestFilteringGeoSpatial
7+
from .test_filtering_global_aggregations import TestFilteringGlobalAggregations
78
from .test_filtering_nested import TestFilteringNested
89
from .test_filtering_post_filter import TestFilteringPostFilter
910
from .test_functional_suggesters import TestFunctionalSuggesters
@@ -29,6 +30,7 @@
2930
'TestFacetedSearch',
3031
'TestFilteringCommon',
3132
'TestFilteringGeoSpatial',
33+
'TestFilteringGlobalAggregations',
3234
'TestFilteringNested',
3335
'TestFilteringPostFilter',
3436
'TestFunctionalSuggesters',

0 commit comments

Comments
 (0)