├── .coveragerc ├── .coveralls.yml ├── .dockerignore ├── .env ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ └── question.md └── workflows │ └── test.yml ├── .gitignore ├── .hgignore ├── .isort.cfg ├── .matyan.ini ├── .pylintrc ├── CHANGELOG.rst ├── CODE_OF_CONDUCT.md ├── CREDITS.rst ├── LICENSE_GPL2.0.txt ├── LICENSE_LGPL_2.1.txt ├── MANIFEST.in ├── README.rst ├── ROADMAP.rst ├── TODOS.rst ├── docker-compose-es-6-8.yml ├── docker-compose-es-7-12.yml ├── docker-compose-es-7-6.yml ├── docker-compose.yml ├── docker ├── backend │ ├── Dockerfile │ ├── README.rst │ └── entrypoint.sh ├── elasticsearch │ ├── Dockerfile │ ├── Dockerfile-ES-6-8 │ ├── Dockerfile-ES-7-12 │ ├── Dockerfile-ES-7-6-2 │ └── elasticsearch.yml └── frontend │ └── Dockerfile ├── docs ├── Makefile ├── advanced_usage_examples.rst ├── basic_usage_examples.rst ├── changelog.rst ├── conf.py ├── conf.py.distrib ├── configuration_tweaks.rst ├── demo.rst ├── dependencies.rst ├── django_elasticsearch_dsl_drf.fields.rst ├── django_elasticsearch_dsl_drf.filter_backends.aggregations.rst ├── django_elasticsearch_dsl_drf.filter_backends.filtering.rst ├── django_elasticsearch_dsl_drf.filter_backends.ordering.rst ├── django_elasticsearch_dsl_drf.filter_backends.rst ├── django_elasticsearch_dsl_drf.filter_backends.search.query_backends.rst ├── django_elasticsearch_dsl_drf.filter_backends.search.rst ├── django_elasticsearch_dsl_drf.filter_backends.suggester.rst ├── django_elasticsearch_dsl_drf.management.commands.rst ├── django_elasticsearch_dsl_drf.management.rst ├── django_elasticsearch_dsl_drf.rst ├── django_elasticsearch_dsl_drf.tests.rst ├── docker.rst ├── documentation.rst.distrib ├── faq.rst ├── filtering_usage_examples.rst ├── frontend_demo.rst ├── global_aggregations.rst ├── index.rst ├── indexing_troubleshooting.rst ├── installing_elasticsearch.rst ├── make.bat ├── misc_usage_examples.rst ├── more_like_this.rst ├── nested_fields_usage_examples.rst ├── pagination.rst ├── quick_start.rst ├── search_backends.rst └── source_backend.rst ├── examples ├── README.rst ├── __init__.py ├── django_elasticsearch_dsl_drf_demo_installer.sh ├── frontend │ ├── .gitignore │ ├── README.rst │ ├── TODOS.rst │ ├── available_scripts.rst │ ├── package-lock.json │ ├── package.json │ ├── public │ │ ├── favicon.ico │ │ ├── index.html │ │ └── manifest.json │ └── src │ │ ├── App.css │ │ ├── App.js │ │ ├── App.test.js │ │ ├── api.js │ │ ├── components │ │ ├── Filter │ │ │ ├── Filter.css │ │ │ └── Filter.js │ │ ├── Pagination │ │ │ ├── Pagination.css │ │ │ └── Pagination.js │ │ └── Result │ │ │ ├── Result.css │ │ │ └── Result.js │ │ ├── constants.js │ │ ├── helpers.js │ │ ├── history.js │ │ ├── index.css │ │ ├── index.js │ │ ├── logo.svg │ │ ├── routes │ │ ├── Detail │ │ │ ├── Detail.css │ │ │ └── Detail.js │ │ └── Search │ │ │ ├── Search.css │ │ │ └── Search.js │ │ └── serviceWorker.js ├── requirements │ ├── README.rst │ ├── base.in │ ├── base.txt │ ├── code_style.in │ ├── code_style.txt │ ├── common.in │ ├── common.txt │ ├── coreapi_coreschema.in │ ├── coreapi_coreschema.txt │ ├── debug.in │ ├── debug.txt │ ├── deployment.in │ ├── deployment.txt │ ├── dev.in │ ├── dev.txt │ ├── django_1_11.in │ ├── django_2_0.in │ ├── django_2_1.in │ ├── django_2_2.in │ ├── django_2_2.txt │ ├── django_2_2_and_elastic_6x.in │ ├── django_2_2_and_elastic_6x.txt │ ├── django_2_2_and_elastic_7x.in │ ├── django_2_2_and_elastic_7x.txt │ ├── django_3_1.in │ ├── django_3_1.txt │ ├── django_3_1_and_elastic_6x.in │ ├── django_3_1_and_elastic_6x.txt │ ├── django_3_1_and_elastic_7x.in │ ├── django_3_1_and_elastic_7x.txt │ ├── django_3_2.in │ ├── django_3_2.txt │ ├── django_3_2_and_elastic_6x.in │ ├── django_3_2_and_elastic_6x.txt │ ├── django_3_2_and_elastic_7x.in │ ├── django_3_2_and_elastic_7x.txt │ ├── docs.in │ ├── docs.txt │ ├── documentation.in │ ├── documentation.txt │ ├── elastic.in │ ├── elastic.txt │ ├── elastic_2x.in │ ├── elastic_5x.in │ ├── elastic_6x.in │ ├── elastic_6x.txt │ ├── elastic_7x.in │ ├── elastic_7x.txt │ ├── elastic_docker.in │ ├── elastic_docker.txt │ ├── none.in │ ├── schema.in │ ├── test.in │ ├── test.txt │ ├── testing.in │ └── testing.txt └── simple │ ├── __init__.py │ ├── assets │ ├── README.rst │ ├── __init__.py │ └── static │ │ ├── css │ │ ├── app.css │ │ ├── foundation.css │ │ └── foundation.min.css │ │ └── js │ │ ├── app.js │ │ └── vendor │ │ ├── foundation.js │ │ ├── foundation.min.js │ │ ├── jquery.js │ │ └── what-input.js │ ├── books │ ├── README.rst │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── constants.py │ ├── management │ │ ├── __init__.py │ │ └── commands │ │ │ ├── __init__.py │ │ │ └── books_create_test_data.py │ ├── migrations │ │ ├── 0001_initial.py │ │ ├── 0002_auto_20170223_1938.py │ │ ├── 0003_book_pages.py │ │ ├── 0004_auto_20170322_2001.py │ │ ├── 0005_auto_20170518_1553.py │ │ ├── 0006_auto_20170619_0428.py │ │ ├── 0007_book_description.py │ │ ├── 0008_book_state.py │ │ ├── 0009_auto_20170626_1331.py │ │ ├── 0010_auto_20170823_1542.py │ │ ├── 0011_auto_20170920_1607.py │ │ ├── 0012_auto_20170921_1540.py │ │ ├── 0013_auto_20171003_1430.py │ │ ├── 0014_auto_20171003_1434.py │ │ ├── 0015_auto_20180622_1617.py │ │ ├── 0016_book_created.py │ │ ├── 0017_location.py │ │ ├── 0018_auto_20200916_1549.py │ │ ├── 0018_auto_20210203_1549.py │ │ ├── 0019_merge_20210219_1534.py │ │ ├── 0020_order_finished.py │ │ ├── 0021_city_capital.py │ │ └── __init__.py │ ├── mixins.py │ ├── models │ │ ├── __init__.py │ │ ├── address.py │ │ ├── author.py │ │ ├── book.py │ │ ├── city.py │ │ ├── continent.py │ │ ├── country.py │ │ ├── galaxy.py │ │ ├── journal.py │ │ ├── location.py │ │ ├── order.py │ │ ├── order_line.py │ │ ├── planet.py │ │ ├── publisher.py │ │ └── tag.py │ ├── templates │ │ └── books │ │ │ ├── add_authors_to_book.html │ │ │ ├── author_list.html │ │ │ ├── author_list_values.html │ │ │ ├── author_list_values_with_counts.html │ │ │ ├── author_list_with_counts.html │ │ │ ├── book_list.html │ │ │ ├── book_list_values.html │ │ │ ├── book_list_with_counts.html │ │ │ ├── create_authors.html │ │ │ ├── index.html │ │ │ ├── publisher_ids.html │ │ │ ├── publisher_list.html │ │ │ └── update_books.html │ ├── tests │ │ ├── README.rst │ │ ├── __init__.py │ │ ├── test_browser.py │ │ └── test_core.py │ ├── urls.py │ └── views.py │ ├── factories │ ├── README.rst │ ├── __init__.py │ ├── auth_user.py │ ├── books_address.py │ ├── books_author.py │ ├── books_book.py │ ├── books_city.py │ ├── books_continent.py │ ├── books_country.py │ ├── books_galaxy.py │ ├── books_journal.py │ ├── books_location.py │ ├── books_order.py │ ├── books_orderline.py │ ├── books_planet.py │ ├── books_publisher.py │ ├── books_tag.py │ ├── constants.py │ └── factory_faker.py │ ├── manage.py │ ├── search_indexes │ ├── __init__.py │ ├── apps.py │ ├── backends │ │ ├── __init__.py │ │ └── nested_continents.py │ ├── constants.py │ ├── documents │ │ ├── __init__.py │ │ ├── address.py │ │ ├── analyzers.py │ │ ├── author.py │ │ ├── book.py │ │ ├── city.py │ │ ├── journal.py │ │ ├── location.py │ │ ├── publisher.py │ │ └── tag.py │ ├── serializers │ │ ├── __init__.py │ │ ├── address.py │ │ ├── author.py │ │ ├── book.py │ │ ├── city.py │ │ ├── journal.py │ │ ├── location.py │ │ ├── publisher.py │ │ └── tag.py │ ├── signals.py │ ├── urls.py │ └── viewsets │ │ ├── __init__.py │ │ ├── address │ │ ├── __init__.py │ │ ├── default.py │ │ └── frontend.py │ │ ├── author.py │ │ ├── book │ │ ├── __init__.py │ │ ├── base.py │ │ ├── compound_search.py │ │ ├── compound_search_boost.py │ │ ├── default.py │ │ ├── default_filter_lookup.py │ │ ├── faceted_filtered.py │ │ ├── frontend.py │ │ ├── functional_suggester.py │ │ ├── ignore_index_errors.py │ │ ├── more_like_this.py │ │ ├── multi_match.py │ │ ├── multi_match_options_phrase_prefix.py │ │ ├── no_records.py │ │ ├── ordering_by_score.py │ │ ├── ordering_by_score_compound_search.py │ │ ├── permissions.py │ │ ├── query_friendly_pagination.py │ │ ├── simple_query_string.py │ │ ├── simple_query_string_boost.py │ │ └── source.py │ │ ├── city.py │ │ ├── journal.py │ │ ├── location.py │ │ ├── publisher.py │ │ └── tag.py │ ├── settings │ ├── README.rst │ ├── __init__.example │ ├── __init__.py │ ├── base.py │ ├── core.py │ ├── dev.py │ ├── dev_elastic_6.py │ ├── docker.py │ ├── docs.py │ ├── local_settings.example │ └── testing.py │ ├── templates │ ├── README.rst │ ├── base.html │ ├── home.html │ └── snippets │ │ ├── article.html │ │ ├── menu_items.html │ │ └── menu_items_exercises.html │ ├── urls.py │ └── wsgi.py ├── pytest.ini ├── requirements.txt ├── runtests.py ├── scripts ├── README.rst ├── build_docs.sh ├── clean_up.sh ├── collectstatic.sh ├── compile_messages.sh ├── compile_requirements.sh ├── coverage.sh ├── create_dirs.sh ├── create_index.sh ├── create_test_data.sh ├── delete_index.sh ├── dist.sh ├── elasticsearch_docker_start.sh ├── elasticsearch_remove_all_indexes.sh ├── elasticsearch_start.sh ├── elasticsearch_stop.sh ├── free_ports.sh ├── frontend.sh ├── install.sh ├── isort.sh ├── make_messages.sh ├── make_pypi_long_description.sh ├── make_release.sh ├── makemigrations.sh ├── manage.sh ├── migrate.sh ├── prepare_docs.sh ├── prepare_project.sh ├── pycodestyle.sh ├── pycodestyle_example.sh ├── pylint.sh ├── pylint_example.sh ├── rebuild_docs.sh ├── rebuild_index.sh ├── reinstall.sh ├── runserver.sh ├── runtests.sh ├── shell.sh ├── test.sh ├── tox.sh ├── uninstall.sh ├── update_index.sh ├── upgrade_requirements.sh ├── vagrant_start.sh ├── vagrant_stop.sh └── yarn_install.sh ├── setup.cfg ├── setup.py ├── src └── django_elasticsearch_dsl_drf │ ├── __init__.py │ ├── analyzers.py │ ├── apps.py │ ├── compat.py │ ├── constants.py │ ├── elasticsearch_helpers.py │ ├── fields │ ├── __init__.py │ ├── common.py │ ├── helpers.py │ └── nested_fields.py │ ├── filter_backends │ ├── __init__.py │ ├── aggregations │ │ ├── __init__.py │ │ ├── bucket_aggregations.py │ │ ├── metrics_aggregations.py │ │ └── pipeline_aggregations.py │ ├── faceted_search.py │ ├── filtering │ │ ├── __init__.py │ │ ├── common.py │ │ ├── geo_spatial.py │ │ ├── ids.py │ │ ├── nested.py │ │ └── post_filter.py │ ├── highlight.py │ ├── mixins.py │ ├── ordering │ │ ├── __init__.py │ │ ├── common.py │ │ └── geo_spatial.py │ ├── search │ │ ├── __init__.py │ │ ├── base.py │ │ ├── compound.py │ │ ├── historical.py │ │ ├── multi_match.py │ │ ├── query_backends │ │ │ ├── __init__.py │ │ │ ├── base.py │ │ │ ├── match.py │ │ │ ├── match_phrase.py │ │ │ ├── match_phrase_prefix.py │ │ │ ├── multi_match.py │ │ │ ├── nested.py │ │ │ └── simple_query_string.py │ │ ├── query_string.py │ │ └── simple_query_string.py │ ├── source.py │ └── suggester │ │ ├── __init__.py │ │ ├── functional.py │ │ └── native.py │ ├── helpers.py │ ├── management │ ├── __init__.py │ └── commands │ │ ├── __init__.py │ │ └── elasticsearch_remove_indexes.py │ ├── pagination.py │ ├── pip_helpers.py │ ├── serializers.py │ ├── tests │ ├── __init__.py │ ├── base.py │ ├── data_mixins.py │ ├── test_elasticsearch_helpers.py │ ├── test_faceted_filtered_search.py │ ├── test_faceted_search.py │ ├── test_filtering_common.py │ ├── test_filtering_geo_spatial.py │ ├── test_filtering_global_aggregations.py │ ├── test_filtering_nested.py │ ├── test_filtering_post_filter.py │ ├── test_functional_suggesters.py │ ├── test_helpers.py │ ├── test_highlight.py │ ├── test_management_commands.py │ ├── test_more_like_this.py │ ├── test_ordering_common.py │ ├── test_ordering_geo_spatial.py │ ├── test_pagination.py │ ├── test_pip_helpers.py │ ├── test_query_friendly_pagination.py │ ├── test_search.py │ ├── test_search_multi_match.py │ ├── test_search_simple_query_string.py │ ├── test_serializers.py │ ├── test_source.py │ ├── test_suggesters.py │ ├── test_utils.py │ ├── test_versions.py │ ├── test_views.py │ └── test_wrappers.py │ ├── utils.py │ ├── versions.py │ ├── viewsets.py │ └── wrappers.py ├── tox.ini └── vagrant ├── README.rst ├── Vagrantfile └── bootstrap.sh /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | relative_files = True 3 | omit = 4 | src/django_elasticsearch_dsl_drf/tests/* 5 | example/simple/settings/* 6 | example/simple/wsgi.py 7 | .tox/ 8 | -------------------------------------------------------------------------------- /.coveralls.yml: -------------------------------------------------------------------------------- 1 | service_name: github-actions 2 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | .benchmarks 2 | .pytest_cache 3 | .tox 4 | build 5 | codebin 6 | dist 7 | docs 8 | docs_src 9 | forks 10 | htmlcov 11 | node_modules 12 | releases 13 | vagrant 14 | -------------------------------------------------------------------------------- /.env: -------------------------------------------------------------------------------- 1 | GITHUB_TOKEN 2 | COVERALLS_REPO_TOKEN 3 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **Environment** 14 | 15 | Python environment: 16 | 1. `pip list` 17 | 2. `python --version` 18 | 19 | Which version of Elasticsearch are you using? 20 | 21 | **To Reproduce** 22 | Steps to reproduce the behavior: 23 | 1. Go to '...' 24 | 2. Click on '....' 25 | 3. Scroll down to '....' 26 | 4. See error 27 | 28 | **Expected behavior** 29 | A clear and concise description of what you expected to happen. 30 | 31 | **Screenshots** 32 | If applicable, add screenshots to help explain your problem. 33 | 34 | **Additional context** 35 | Add any other context about the problem here. 36 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question 3 | about: When you have a question like `is [SOMETHING] possibe` or `how to do [SOMETHING]` 4 | title: '' 5 | labels: question 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Questions** 11 | 12 | Before raising a issue like `is [SOMETHING] possible` or `how to do [SOMETHING]` make sure you have read the [documentation](https://django-elasticsearch-dsl-drf.readthedocs.io). Some quick answers you might find in [FAQ](https://github.com/barseghyanartur/django-elasticsearch-dsl-drf/blob/master/docs/faq.rst). 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | .hgignore~ 3 | .gitignore~ 4 | .hg/ 5 | .hgtags 6 | .tox/ 7 | .travis.yml~ 8 | .cache/ 9 | .coverage* 10 | /htmlcov/ 11 | *.py,cover 12 | .idea/ 13 | /vagrant/.vagrant/ 14 | .pytest_cache/ 15 | /coverage.xml 16 | 17 | node_modules/ 18 | MANIFEST.in~ 19 | MIND_BUCKET.rst 20 | codebin/ 21 | codebin.py 22 | /tmp/ 23 | .zip 24 | /demo/ 25 | /demos/ 26 | /release/ 27 | /releases/ 28 | /deploy/ 29 | /examples/db/ 30 | /var/ 31 | /forks/ 32 | /examples/tmp/ 33 | /examples/logs/ 34 | /examples/media/ 35 | /examples/media/cache/ 36 | /examples/static/ 37 | /builddocs/ 38 | /builddocs.zip 39 | /build/ 40 | /dist/ 41 | /src/django_elasticsearch_dsl_drf.egg-info 42 | /src/django_elasticsearch_dsl_drf/filter_backends/aggregations.py 43 | #/examples/simple/settings/__init__.py 44 | /examples/simple/settings/local_settings.py 45 | yarn.lock 46 | matyan.log* 47 | -------------------------------------------------------------------------------- /.hgignore: -------------------------------------------------------------------------------- 1 | syntax: regexp 2 | \.pyc$ 3 | \.hgignore~ 4 | \.gitignore~ 5 | \.git/ 6 | \.tox/ 7 | \.travis\.yml~ 8 | \.cache/ 9 | \.coverage$ 10 | \.coverage 11 | ^htmlcov/ 12 | \.py,cover 13 | \.idea/ 14 | ^vagrant/\.vagrant 15 | ^\.pytest_cache/ 16 | node_modules/ 17 | yarn-error\.log 18 | ^coverage\.xml 19 | 20 | ^MANIFEST\.in~ 21 | ^tmp/ 22 | \.zip 23 | ^release/ 24 | ^var/ 25 | ^releases/ 26 | ^demo/ 27 | #^codebin/ 28 | ^deploy/ 29 | ^examples/db/ 30 | ^examples/tmp/ 31 | ^examples/logs/ 32 | ^examples/media/ 33 | ^examples/media/cache/ 34 | ^examples/static/ 35 | ^examples/simple/settings/local_settings\.py 36 | #^examples/simple/settings/__init__\.py 37 | ^builddocs/ 38 | ^builddocs\.zip 39 | ^build/ 40 | ^dist/ 41 | ^src/django_elasticsearch_dsl_drf\.egg-info 42 | \.DS_Store 43 | ^examples/frontend/node_modules/ 44 | -------------------------------------------------------------------------------- /.isort.cfg: -------------------------------------------------------------------------------- 1 | [settings] 2 | line_length=80 3 | force_to_top= 4 | skip= 5 | known_future_library= 6 | known_standard_library= 7 | known_third_party= 8 | known_first_party=django_elasticsearch_dsl_drf 9 | indent=' ' 10 | multi_line_output=3 11 | length_sort=1 12 | forced_separate=django.contrib,django.utils 13 | default_section=django_elasticsearch_dsl_drf 14 | -------------------------------------------------------------------------------- /.matyan.ini: -------------------------------------------------------------------------------- 1 | [BranchTypes] 2 | feature: Feature 3 | bugfix: Bugfix 4 | hotfix: Hotfix 5 | deprecation: Deprecation 6 | 7 | [OtherBranchType] 8 | other: Other 9 | 10 | [Unreleased] 11 | unreleased: Unreleased 12 | 13 | [IgnoreCommits] 14 | exact: more 15 | clean up 16 | code comments 17 | more on docs 18 | repo 19 | working 20 | more on 21 | wip 22 | commit 23 | prefix: more on 24 | continue on 25 | prepare 26 | prpare 27 | -------------------------------------------------------------------------------- /.pylintrc: -------------------------------------------------------------------------------- 1 | [MASTER] 2 | ignore= 3 | disable=R,C 4 | init-hook='import sys; import os; sys.path.append(os.path.abspath("src")); sys.path.append(os.path.abspath("examples")); sys.path.append(os.path.abspath("examples/simple"));' 5 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.rst 2 | include LICENSE_GPL2.0.txt 3 | include LICENSE_LGPL_2.1.txt 4 | include CHANGELOG.rst 5 | 6 | recursive-include src/django_elasticsearch_dsl_drf * 7 | -------------------------------------------------------------------------------- /ROADMAP.rst: -------------------------------------------------------------------------------- 1 | Roadmap 2 | ======= 3 | Road-map/upcoming releases. 4 | 5 | See `GitHub issues 6 | `_ 7 | for a complete list of TODOs. 8 | -------------------------------------------------------------------------------- /docker-compose-es-6-8.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | 5 | elasticsearch: 6 | container_name: django_elasticsearch_dsl_drf_elasticsearch_es_6_8 7 | build: 8 | context: . 9 | dockerfile: ./docker/elasticsearch/Dockerfile-ES-6-8 10 | image: docker.elastic.co/elasticsearch/elasticsearch:6.8.15 11 | volumes: 12 | - esdata68:/usr/share/elasticsearch/data 13 | ports: 14 | - "9200:9200" 15 | - "9300:9300" 16 | environment: 17 | # - bootstrap.memory_lock=true 18 | - discovery.type=single-node 19 | - xpack.security.enabled=false 20 | - cluster.routing.allocation.disk.watermark.low=97% 21 | - cluster.routing.allocation.disk.watermark.high=98% 22 | - cluster.routing.allocation.disk.watermark.flood_stage=99% 23 | - "ES_JAVA_OPTS=-Xms512m -Xmx512m" 24 | 25 | volumes: 26 | esdata68: 27 | -------------------------------------------------------------------------------- /docker-compose-es-7-12.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | 5 | elasticsearch: 6 | container_name: django_elasticsearch_dsl_drf_elasticsearch_es_7_12 7 | build: 8 | context: . 9 | dockerfile: ./docker/elasticsearch/Dockerfile-ES-7-12 10 | image: docker.elastic.co/elasticsearch/elasticsearch:7.12.1 11 | volumes: 12 | - esdata712:/usr/share/elasticsearch/data 13 | ports: 14 | - "9200:9200" 15 | - "9300:9300" 16 | environment: 17 | # - bootstrap.memory_lock=true 18 | - discovery.type=single-node 19 | - xpack.security.enabled=false 20 | - cluster.routing.allocation.disk.watermark.low=97% 21 | - cluster.routing.allocation.disk.watermark.high=98% 22 | - cluster.routing.allocation.disk.watermark.flood_stage=99% 23 | - "ES_JAVA_OPTS=-Xms512m -Xmx512m" 24 | 25 | volumes: 26 | esdata712: 27 | -------------------------------------------------------------------------------- /docker-compose-es-7-6.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | 5 | elasticsearch: 6 | container_name: django_elasticsearch_dsl_drf_elasticsearch_es_7_6 7 | build: 8 | context: . 9 | dockerfile: ./docker/elasticsearch/Dockerfile-ES-7-6-2 10 | image: docker.elastic.co/elasticsearch/elasticsearch:7.6.2 11 | volumes: 12 | - esdata76:/usr/share/elasticsearch/data 13 | ports: 14 | - "9200:9200" 15 | - "9300:9300" 16 | environment: 17 | # - bootstrap.memory_lock=true 18 | - discovery.type=single-node 19 | - xpack.security.enabled=false 20 | - cluster.routing.allocation.disk.watermark.low=97% 21 | - cluster.routing.allocation.disk.watermark.high=98% 22 | - cluster.routing.allocation.disk.watermark.flood_stage=99% 23 | - "ES_JAVA_OPTS=-Xms512m -Xmx512m" 24 | 25 | volumes: 26 | esdata76: 27 | -------------------------------------------------------------------------------- /docker/backend/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM docker.io/python:3.9-slim-bullseye 2 | ENV PYTHONUNBUFFERED 1 3 | 4 | RUN apt-get update 5 | RUN apt-get install -y build-essential 6 | RUN apt-get install -y cmake 7 | RUN apt-get install -y libpq-dev 8 | #RUN apt-get install -y python-dev 9 | #RUN apt-get install -y python-pip 10 | #RUN apt-get install -y python-imaging 11 | RUN apt-get install -y mc 12 | RUN apt-get install -y nano 13 | 14 | RUN pip install pip --upgrade 15 | RUN pip install virtualenv 16 | 17 | RUN mkdir /backend 18 | WORKDIR /backend 19 | ADD examples/requirements/ /backend/requirements/ 20 | RUN pip install -r /backend/requirements/dev.txt 21 | RUN pip install -r /backend/requirements/elastic_docker.txt 22 | COPY . /backend/ 23 | RUN python /backend/setup.py develop 24 | -------------------------------------------------------------------------------- /docker/backend/README.rst: -------------------------------------------------------------------------------- 1 | Common commands 2 | --------------- 3 | Connect to backend 4 | ~~~~~~~~~~~~~~~~~~ 5 | .. code-block:: 6 | 7 | docker exec -ti django_elasticsearch_dsl_drf_backend /bin/bash 8 | -------------------------------------------------------------------------------- /docker/backend/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Create dirs if necessary 4 | echo "Creating dirs" 5 | ./scripts/create_dirs.sh 6 | 7 | # Apply database migrations 8 | echo "Apply database migrations" 9 | ./examples/simple/manage.py migrate --noinput --settings=settings.docker 10 | 11 | # Create search index 12 | echo "Create search index" 13 | ./examples/simple/manage.py search_index --create -f --settings=settings.docker 14 | 15 | # Create test data 16 | echo "Apply database migrations" 17 | ./examples/simple/manage.py books_create_test_data --settings=settings.docker 18 | 19 | # Create search index 20 | echo "Create search index" 21 | ./examples/simple/manage.py search_index --rebuild -f --settings=settings.docker 22 | 23 | # Start server 24 | echo "Starting server" 25 | python ./examples/simple/manage.py runserver 0.0.0.0:8000 --settings=settings.docker --traceback -v 3 26 | -------------------------------------------------------------------------------- /docker/elasticsearch/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM docker.elastic.co/elasticsearch/elasticsearch:7.5.2 2 | ADD ./docker/elasticsearch/elasticsearch.yml /usr/share/elasticsearch/config/ 3 | USER root 4 | RUN chown elasticsearch:elasticsearch config/elasticsearch.yml 5 | USER elasticsearch 6 | -------------------------------------------------------------------------------- /docker/elasticsearch/Dockerfile-ES-6-8: -------------------------------------------------------------------------------- 1 | FROM docker.elastic.co/elasticsearch/elasticsearch:6.8.15 2 | ADD ./docker/elasticsearch/elasticsearch.yml /usr/share/elasticsearch/config/ 3 | USER root 4 | RUN chown elasticsearch:elasticsearch config/elasticsearch.yml 5 | USER elasticsearch 6 | -------------------------------------------------------------------------------- /docker/elasticsearch/Dockerfile-ES-7-12: -------------------------------------------------------------------------------- 1 | FROM docker.elastic.co/elasticsearch/elasticsearch:7.12.1 2 | ADD ./docker/elasticsearch/elasticsearch.yml /usr/share/elasticsearch/config/ 3 | USER root 4 | RUN chown elasticsearch:elasticsearch config/elasticsearch.yml 5 | USER elasticsearch 6 | -------------------------------------------------------------------------------- /docker/elasticsearch/Dockerfile-ES-7-6-2: -------------------------------------------------------------------------------- 1 | FROM docker.elastic.co/elasticsearch/elasticsearch:7.6.2 2 | ADD ./docker/elasticsearch/elasticsearch.yml /usr/share/elasticsearch/config/ 3 | USER root 4 | RUN chown elasticsearch:elasticsearch config/elasticsearch.yml 5 | USER elasticsearch 6 | -------------------------------------------------------------------------------- /docker/elasticsearch/elasticsearch.yml: -------------------------------------------------------------------------------- 1 | xpack.security.enabled: false 2 | http.host: 0.0.0.0 3 | transport.host: 127.0.0.1 4 | discovery.type: single-node 5 | -------------------------------------------------------------------------------- /docker/frontend/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM docker.io/node:8 2 | 3 | RUN apt-get update 4 | RUN apt-get install -y mc 5 | RUN apt-get install -y nano 6 | 7 | RUN mkdir /frontend 8 | 9 | ADD examples/frontend/package.json /frontend/ 10 | ADD . /frontend/ 11 | 12 | WORKDIR /frontend 13 | RUN npm install 14 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/configuration_tweaks.rst: -------------------------------------------------------------------------------- 1 | ==================== 2 | Configuration tweaks 3 | ==================== 4 | Ignore certain Elasticsearch exceptions 5 | --------------------------------------- 6 | .. code-block:: python 7 | 8 | class BookIgnoreIndexErrorsDocumentViewSet(DocumentViewSet): 9 | 10 | # ... 11 | ignore = [404] 12 | # ... 13 | -------------------------------------------------------------------------------- /docs/demo.rst: -------------------------------------------------------------------------------- 1 | Demo 2 | ==== 3 | Run demo locally 4 | ---------------- 5 | In order to be able to quickly evaluate the ``django-elasticsearch-dsl-drf``, 6 | a demo app (with a quick installer) has been created (works on Ubuntu/Debian, 7 | may work on other Linux systems as well, although not guaranteed). Follow the 8 | instructions below for having the demo running within a minute. 9 | 10 | Prerequisites 11 | ------------- 12 | - Python 3 13 | - Docker 14 | 15 | Grab and run Elasticsearch: 16 | 17 | .. code-block:: sh 18 | 19 | docker pull docker.elastic.co/elasticsearch/elasticsearch:5.5.3 20 | docker run -p 9200:9200 -e "discovery.type=single-node" -e "xpack.security.enabled=false" docker.elastic.co/elasticsearch/elasticsearch:5.5.3 21 | 22 | Grab and run the latest ``django_elasticsearch_dsl_drf_demo_installer.sh``: 23 | 24 | .. code-block:: sh 25 | 26 | wget -O - https://raw.github.com/barseghyanartur/django-elasticsearch-dsl-drf/master/examples/django_elasticsearch_dsl_drf_demo_installer.sh | bash 27 | 28 | Open your browser and test the app. 29 | 30 | - URL: http://127.0.0.1:8001/search/ 31 | -------------------------------------------------------------------------------- /docs/django_elasticsearch_dsl_drf.fields.rst: -------------------------------------------------------------------------------- 1 | django\_elasticsearch\_dsl\_drf.fields package 2 | ============================================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | django\_elasticsearch\_dsl\_drf.fields.common module 8 | ---------------------------------------------------- 9 | 10 | .. automodule:: django_elasticsearch_dsl_drf.fields.common 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | django\_elasticsearch\_dsl\_drf.fields.helpers module 16 | ----------------------------------------------------- 17 | 18 | .. automodule:: django_elasticsearch_dsl_drf.fields.helpers 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | django\_elasticsearch\_dsl\_drf.fields.nested\_fields module 24 | ------------------------------------------------------------ 25 | 26 | .. automodule:: django_elasticsearch_dsl_drf.fields.nested_fields 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | Module contents 32 | --------------- 33 | 34 | .. automodule:: django_elasticsearch_dsl_drf.fields 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | -------------------------------------------------------------------------------- /docs/django_elasticsearch_dsl_drf.filter_backends.aggregations.rst: -------------------------------------------------------------------------------- 1 | django\_elasticsearch\_dsl\_drf.filter\_backends.aggregations package 2 | ===================================================================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | django\_elasticsearch\_dsl\_drf.filter\_backends.aggregations.bucket\_aggregations module 8 | ----------------------------------------------------------------------------------------- 9 | 10 | .. automodule:: django_elasticsearch_dsl_drf.filter_backends.aggregations.bucket_aggregations 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | django\_elasticsearch\_dsl\_drf.filter\_backends.aggregations.metrics\_aggregations module 16 | ------------------------------------------------------------------------------------------ 17 | 18 | .. automodule:: django_elasticsearch_dsl_drf.filter_backends.aggregations.metrics_aggregations 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | django\_elasticsearch\_dsl\_drf.filter\_backends.aggregations.pipeline\_aggregations module 24 | ------------------------------------------------------------------------------------------- 25 | 26 | .. automodule:: django_elasticsearch_dsl_drf.filter_backends.aggregations.pipeline_aggregations 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | Module contents 32 | --------------- 33 | 34 | .. automodule:: django_elasticsearch_dsl_drf.filter_backends.aggregations 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | -------------------------------------------------------------------------------- /docs/django_elasticsearch_dsl_drf.filter_backends.ordering.rst: -------------------------------------------------------------------------------- 1 | django\_elasticsearch\_dsl\_drf.filter\_backends.ordering package 2 | ================================================================= 3 | 4 | Submodules 5 | ---------- 6 | 7 | django\_elasticsearch\_dsl\_drf.filter\_backends.ordering.common module 8 | ----------------------------------------------------------------------- 9 | 10 | .. automodule:: django_elasticsearch_dsl_drf.filter_backends.ordering.common 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | django\_elasticsearch\_dsl\_drf.filter\_backends.ordering.geo\_spatial module 16 | ----------------------------------------------------------------------------- 17 | 18 | .. automodule:: django_elasticsearch_dsl_drf.filter_backends.ordering.geo_spatial 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: django_elasticsearch_dsl_drf.filter_backends.ordering 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/django_elasticsearch_dsl_drf.filter_backends.suggester.rst: -------------------------------------------------------------------------------- 1 | django\_elasticsearch\_dsl\_drf.filter\_backends.suggester package 2 | ================================================================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | django\_elasticsearch\_dsl\_drf.filter\_backends.suggester.functional module 8 | ---------------------------------------------------------------------------- 9 | 10 | .. automodule:: django_elasticsearch_dsl_drf.filter_backends.suggester.functional 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | django\_elasticsearch\_dsl\_drf.filter\_backends.suggester.native module 16 | ------------------------------------------------------------------------ 17 | 18 | .. automodule:: django_elasticsearch_dsl_drf.filter_backends.suggester.native 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: django_elasticsearch_dsl_drf.filter_backends.suggester 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/django_elasticsearch_dsl_drf.management.commands.rst: -------------------------------------------------------------------------------- 1 | django\_elasticsearch\_dsl\_drf.management.commands package 2 | =========================================================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | django\_elasticsearch\_dsl\_drf.management.commands.elasticsearch\_remove\_indexes module 8 | ----------------------------------------------------------------------------------------- 9 | 10 | .. automodule:: django_elasticsearch_dsl_drf.management.commands.elasticsearch_remove_indexes 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | Module contents 16 | --------------- 17 | 18 | .. automodule:: django_elasticsearch_dsl_drf.management.commands 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | -------------------------------------------------------------------------------- /docs/django_elasticsearch_dsl_drf.management.rst: -------------------------------------------------------------------------------- 1 | django\_elasticsearch\_dsl\_drf.management package 2 | ================================================== 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 20 9 | 10 | django_elasticsearch_dsl_drf.management.commands 11 | 12 | Module contents 13 | --------------- 14 | 15 | .. automodule:: django_elasticsearch_dsl_drf.management 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | -------------------------------------------------------------------------------- /docs/docker.rst: -------------------------------------------------------------------------------- 1 | docker run -it django_elasticsearch_dsl_drf_frontend /bin/bash 2 | -------------------------------------------------------------------------------- /docs/documentation.rst.distrib: -------------------------------------------------------------------------------- 1 | 2 | Project documentation 3 | ===================== 4 | Contents: 5 | 6 | .. contents:: Table of Contents 7 | 8 | .. toctree:: 9 | :maxdepth: 20 10 | 11 | index 12 | dependencies 13 | installing_elasticsearch 14 | quick_start 15 | filtering_usage_examples 16 | search_backends 17 | basic_usage_examples 18 | advanced_usage_examples 19 | nested_fields_usage_examples 20 | more_like_this 21 | global_aggregations 22 | configuration_tweaks 23 | source_backend 24 | pagination 25 | indexing_troubleshooting 26 | faq 27 | demo 28 | frontend_demo 29 | changelog 30 | django_elasticsearch_dsl_drf 31 | 32 | Indices and tables 33 | ================== 34 | 35 | * :ref:`genindex` 36 | * :ref:`modindex` 37 | * :ref:`search` 38 | -------------------------------------------------------------------------------- /docs/installing_elasticsearch.rst: -------------------------------------------------------------------------------- 1 | Installing Elasticsearch 2 | ======================== 3 | For development and testing purposes, it's often handy to be able to 4 | quickly switch between different Elasticsearch versions. Since this packages 5 | supports 2.x, 5.x and 6.x branches, you could make use of 6 | the following boxes/containers for development and testing. 7 | 8 | .. note:: 9 | 10 | As of ``django-elasticsearch-dsl-drf`` 0.19, support for Elasticsearch 11 | versions prior 6.x has been dropped. 12 | 13 | For all containers/boxes mentioned below, no authentication is required (for 14 | Elasticsearch). 15 | 16 | Docker 17 | ------ 18 | Using ``docker-compose`` (persistent): 19 | 20 | .. code-block:: sh 21 | 22 | docker-compose up elasticsearch 23 | 24 | 6.x 25 | ~~~ 26 | **6.3.2** 27 | 28 | .. code-block:: sh 29 | 30 | docker pull docker.elastic.co/elasticsearch/elasticsearch:6.3.2 31 | docker run -p 9200:9200 -e "discovery.type=single-node" -e "xpack.security.enabled=false" docker.elastic.co/elasticsearch/elasticsearch:6.3.2 32 | 33 | **6.4.0** 34 | 35 | .. code-block:: sh 36 | 37 | docker pull docker.elastic.co/elasticsearch/elasticsearch:6.4.0 38 | docker run -p 9200:9200 -e "discovery.type=single-node" -e "xpack.security.enabled=false" docker.elastic.co/elasticsearch/elasticsearch:6.4.0 39 | 40 | 7.x 41 | ~~~ 42 | **7.3.0** 43 | 44 | .. code-block:: sh 45 | 46 | docker pull docker.elastic.co/elasticsearch/elasticsearch:7.3.0 47 | docker run -p 9200:9200 -e "discovery.type=single-node" -e "xpack.security.enabled=false" docker.elastic.co/elasticsearch/elasticsearch:7.3.0 48 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | 13 | if "%1" == "" goto help 14 | 15 | %SPHINXBUILD% >NUL 2>NUL 16 | if errorlevel 9009 ( 17 | echo. 18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 19 | echo.installed, then set the SPHINXBUILD environment variable to point 20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 21 | echo.may add the Sphinx directory to PATH. 22 | echo. 23 | echo.If you don't have Sphinx installed, grab it from 24 | echo.http://sphinx-doc.org/ 25 | exit /b 1 26 | ) 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/misc_usage_examples.rst: -------------------------------------------------------------------------------- 1 | ===================== 2 | Various handy helpers 3 | ===================== 4 | 5 | Contents: 6 | 7 | .. contents:: Table of Contents 8 | 9 | More like this 10 | ============== 11 | 12 | To get more-like-this results on a random registered model, do as follows: 13 | 14 | .. code-block:: python 15 | 16 | from django_elasticsearch_dsl_drf.helpers import more_like_this 17 | from books.models import Book 18 | book = Book.objects.first() 19 | similar_books = more_like_this( 20 | book, 21 | ['title', 'description', 'summary'] 22 | ) 23 | 24 | 25 | Customize results as follows: 26 | 27 | .. code-block:: python 28 | 29 | from django_elasticsearch_dsl_drf.helpers import more_like_this 30 | from elasticsearch_dsl.query import Q 31 | from books.models import Book 32 | book = Book.objects.first() 33 | query = Q('bool', must_not=Q('term', **{'state.raw': 'cancelled'})) 34 | similar_books = more_like_this( 35 | book, 36 | query=query, 37 | fields=['title', 'description', 'summary'], 38 | min_term_freq=2, 39 | min_doc_freq=1, 40 | ) 41 | -------------------------------------------------------------------------------- /examples/README.rst: -------------------------------------------------------------------------------- 1 | Example project for `django-elasticsearch-dsl-drf` 2 | ================================================== 3 | -------------------------------------------------------------------------------- /examples/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/django-elasticsearch-dsl-drf/d83900f2c92b38b00423065795b146434c5a5bf7/examples/__init__.py -------------------------------------------------------------------------------- /examples/django_elasticsearch_dsl_drf_demo_installer.sh: -------------------------------------------------------------------------------- 1 | wget -O django_elasticsearch_dsl_drf_demo_installer.tar.gz https://github.com/barseghyanartur/django-elasticsearch-dsl-drf/archive/master.tar.gz 2 | virtualenv django-elasticsearch-dsl-drf-env 3 | source django-elasticsearch-dsl-drf-env/bin/activate 4 | mkdir django_elasticsearch_dsl_drf_demo_installer/ 5 | tar -xvf django_elasticsearch_dsl_drf_demo_installer.tar.gz -C django_elasticsearch_dsl_drf_demo_installer 6 | cd django_elasticsearch_dsl_drf_demo_installer/django-elasticsearch-dsl-drf-stable/examples/simple/ 7 | pip install -r ../../requirements.txt 8 | pip install https://github.com/barseghyanartur/django-elasticsearch-dsl-drf/archive/master.tar.gz 9 | mkdir ../media/ 10 | mkdir ../media/static/ 11 | mkdir ../static/ 12 | mkdir ../db/ 13 | mkdir ../logs/ 14 | mkdir ../tmp/ 15 | cp settings/local_settings.example settings/local_settings.py 16 | ./manage.py migrate --noinput --traceback -v 3 17 | ./manage.py collectstatic --noinput --traceback -v 3 18 | ./manage.py books_create_test_data --number=20 --traceback -v 3 19 | ./manage.py runserver 0.0.0.0:8001 --traceback -v 3 20 | -------------------------------------------------------------------------------- /examples/frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /examples/frontend/TODOS.rst: -------------------------------------------------------------------------------- 1 | + Auto-complete 2 | + Pagination 3 | + Reset pagination 4 | + Range plugin 5 | + Date range plugin 6 | - Write custom filter backends to handle multiple choices for range and 7 | date range plugins. 8 | -------------------------------------------------------------------------------- /examples/frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "axios": "^0.18.0", 7 | "classnames": "^2.2.6", 8 | "history": "^4.7.2", 9 | "picnic": "^6.5.0", 10 | "react": "^16.6.3", 11 | "react-autosuggest": "^9.4.2", 12 | "react-bootstrap": "^0.32.4", 13 | "react-dom": "^16.6.3", 14 | "react-router": "^4.3.1", 15 | "react-router-dom": "^4.3.1", 16 | "react-scripts": "2.1.1", 17 | "serve": "^10.1.1", 18 | "throttle-debounce": "^2.0.1" 19 | }, 20 | "scripts": { 21 | "dev": "BROWSER=none react-scripts start", 22 | "start": "serve --single ./build", 23 | "build": "react-scripts build", 24 | "test": "react-scripts test", 25 | "eject": "react-scripts eject" 26 | }, 27 | "eslintConfig": { 28 | "extends": "react-app" 29 | }, 30 | "browserslist": [ 31 | ">0.2%", 32 | "not dead", 33 | "not ie <= 11", 34 | "not op_mini all" 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /examples/frontend/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/django-elasticsearch-dsl-drf/d83900f2c92b38b00423065795b146434c5a5bf7/examples/frontend/public/favicon.ico -------------------------------------------------------------------------------- /examples/frontend/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 22 | React App 23 | 24 | 25 | 28 |
29 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /examples/frontend/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": ".", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /examples/frontend/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | animation: App-logo-spin infinite 20s linear; 7 | height: 40vmin; 8 | } 9 | 10 | .App-header { 11 | background-color: #282c34; 12 | min-height: 100vh; 13 | display: flex; 14 | flex-direction: column; 15 | align-items: center; 16 | justify-content: center; 17 | font-size: calc(10px + 2vmin); 18 | color: white; 19 | } 20 | 21 | .App-link { 22 | color: #61dafb; 23 | } 24 | 25 | @keyframes App-logo-spin { 26 | from { 27 | transform: rotate(0deg); 28 | } 29 | to { 30 | transform: rotate(360deg); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /examples/frontend/src/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { 3 | BrowserRouter, 4 | Route, 5 | Switch, 6 | } from 'react-router-dom'; 7 | import "picnic/picnic.min.css"; 8 | 9 | import Search from './routes/Search/Search'; 10 | import Detail from './routes/Detail/Detail'; 11 | 12 | import logo from './logo.svg'; 13 | import './App.css'; 14 | 15 | class App extends Component { 16 | 17 | constructor(props) { 18 | super(props); 19 | this.updateQuery = this.updateQuery.bind(this); 20 | this.state = { 21 | query: '' 22 | } 23 | } 24 | 25 | updateQuery(query) { 26 | this.setState({query}); 27 | } 28 | 29 | render() { 30 | return ( 31 | 32 | {/**/} 33 |
34 | 42 | } 43 | /> 44 | 45 | {/**/} 46 |
47 |
48 | ); 49 | } 50 | } 51 | 52 | export default App; 53 | -------------------------------------------------------------------------------- /examples/frontend/src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render(, div); 8 | ReactDOM.unmountComponentAtNode(div); 9 | }); 10 | -------------------------------------------------------------------------------- /examples/frontend/src/components/Filter/Filter.css: -------------------------------------------------------------------------------- 1 | .filters-wrapper { 2 | position: absolute; 3 | } 4 | .filter-wrapper { 5 | 6 | } -------------------------------------------------------------------------------- /examples/frontend/src/components/Pagination/Pagination.css: -------------------------------------------------------------------------------- 1 | .pagination-wrapper { 2 | 3 | } 4 | 5 | .pagination-wrapper a { 6 | margin: 0; 7 | padding: 0 5px; 8 | } 9 | -------------------------------------------------------------------------------- /examples/frontend/src/components/Pagination/Pagination.js: -------------------------------------------------------------------------------- 1 | import React, { Fragment } from 'react'; 2 | 3 | import './Pagination.css'; 4 | 5 | 6 | class Pagination extends React.Component { 7 | 8 | render() { 9 | const { count, pageSize, updatePageNumber, currentPage } = this.props; 10 | const pages = Math.ceil(count / pageSize); 11 | return ( 12 | 13 |
14 | {[...Array(pages).keys()].map(p => { 15 | const page = p + 1; 16 | if (currentPage === page) { 17 | return ( 18 | {page} 19 | ); 20 | } else { 21 | return ( 22 | { 23 | event.preventDefault(); 24 | updatePageNumber(page) 25 | }}> 26 | {page} 27 | 28 | ); 29 | } 30 | })} 31 |
32 |
33 | ); 34 | } 35 | } 36 | 37 | 38 | export default Pagination; 39 | -------------------------------------------------------------------------------- /examples/frontend/src/components/Result/Result.css: -------------------------------------------------------------------------------- 1 | .results-wrapper { 2 | 3 | } 4 | .results-wrapper .inner { 5 | /*position: fixed;*/ 6 | /*margin: 0 auto;*/ 7 | } 8 | .result-wrapper { 9 | 10 | } 11 | 12 | .result-wrapper ul { 13 | margin: 0; 14 | padding: 0; 15 | } 16 | 17 | .result-wrapper ul li { 18 | margin: 0; 19 | padding: 0; 20 | } 21 | -------------------------------------------------------------------------------- /examples/frontend/src/components/Result/Result.js: -------------------------------------------------------------------------------- 1 | import React, { Fragment } from 'react'; 2 | import { Link } from 'react-router-dom'; 3 | 4 | import './Result.css'; 5 | 6 | 7 | class Result extends React.Component { 8 | 9 | renderList(tags) { 10 | return ( 11 | 12 |
    13 | { 14 | tags.map( 15 | function(tag, index) { 16 | return
  • {tag}
  • ; 17 | } 18 | ) 19 | } 20 |
21 |
22 | ) 23 | } 24 | 25 | render() { 26 | const { id, title, state, authors, isbn, summary, tags, globalState } = this.props; 27 | return ( 28 | 29 |
30 | 31 |

{title}

32 | 33 | {/* 34 |

{summary}

35 | {this.renderList(tags)} 36 | {this.renderList(authors)} 37 | */} 38 |
39 |
40 | ) 41 | } 42 | } 43 | 44 | 45 | export default Result; 46 | -------------------------------------------------------------------------------- /examples/frontend/src/constants.js: -------------------------------------------------------------------------------- 1 | const constants = { 2 | api: { 3 | url: 'http://localhost:8000', // django-elasticsearch-dsl-drf URL host 4 | searchRoute: '/search/books-frontend/', // Search route 5 | searchRouteParams: 'facet=publisher' + // Default search params 6 | '&facet=status' + 7 | '&facet=price' + 8 | '&facet=publication_date', 9 | rangeFilters: ['price', 'publication_date',], 10 | searchPageSize: 10, 11 | suggestionsRoute: '/search/books-frontend/suggest/', // Suggestions route 12 | suggester: 'title_suggest', 13 | showZeroCountFacets: true, 14 | } 15 | }; 16 | 17 | export default constants; 18 | -------------------------------------------------------------------------------- /examples/frontend/src/helpers.js: -------------------------------------------------------------------------------- 1 | export function getQueryStringParams(query) { 2 | return query 3 | ? (/^[?#]/.test(query) ? query.slice(1) : query) 4 | .split('&') 5 | .reduce((params, param) => { 6 | let [key, value] = param.split('='); 7 | params[key] = value ? decodeURIComponent(value.replace(/\+/g, ' ')) : ''; 8 | return params; 9 | }, {} 10 | ) 11 | : {} 12 | } 13 | -------------------------------------------------------------------------------- /examples/frontend/src/history.js: -------------------------------------------------------------------------------- 1 | import { createBrowserHistory } from 'history'; 2 | 3 | export default createBrowserHistory(); 4 | -------------------------------------------------------------------------------- /examples/frontend/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", 5 | "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", 6 | sans-serif; 7 | -webkit-font-smoothing: antialiased; 8 | -moz-osx-font-smoothing: grayscale; 9 | } 10 | 11 | code { 12 | font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", 13 | monospace; 14 | } 15 | -------------------------------------------------------------------------------- /examples/frontend/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import * as serviceWorker from './serviceWorker'; 6 | 7 | ReactDOM.render(, document.getElementById('root')); 8 | 9 | // If you want your app to work offline and load faster, you can change 10 | // unregister() to register() below. Note this comes with some pitfalls. 11 | // Learn more about service workers: http://bit.ly/CRA-PWA 12 | serviceWorker.unregister(); 13 | -------------------------------------------------------------------------------- /examples/frontend/src/routes/Detail/Detail.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #f9f9f9; 3 | } 4 | 5 | .detail-wrapper { 6 | width: 500px; 7 | text-align: center; 8 | vertical-align: middle; 9 | margin: 200px auto; 10 | } 11 | -------------------------------------------------------------------------------- /examples/requirements/README.rst: -------------------------------------------------------------------------------- 1 | requirements 2 | ============ 3 | Project requirements. Consists of loose files, combined with each other. 4 | 5 | code_style.txt 6 | -------------- 7 | Code style checkers. 8 | 9 | common.txt 10 | ---------- 11 | Common (non Django specific) packages. 12 | 13 | debug.txt 14 | --------- 15 | Common (non Django specific) packages. 16 | 17 | dev.txt 18 | ------- 19 | Everything needed to development environment, including debugging tools, 20 | documentation generators, Django packages, testing packages, code style 21 | packages. 22 | 23 | django_1_8.txt 24 | -------------- 25 | What's necessary to run Django. 26 | 27 | docs.txt 28 | -------- 29 | Documentation related (generators). 30 | 31 | test.txt 32 | -------- 33 | What's necessary to run the tests. 34 | 35 | testing.txt 36 | ----------- 37 | A combination of Django and test requirements. 38 | -------------------------------------------------------------------------------- /examples/requirements/base.in: -------------------------------------------------------------------------------- 1 | -r django_3_2.in 2 | -------------------------------------------------------------------------------- /examples/requirements/base.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile with python 3.9 3 | # To update, run: 4 | # 5 | # pip-compile base.in 6 | # 7 | asgiref==3.4.1 8 | # via django 9 | django==3.2.5 10 | # via 11 | # -r django_3_2.in 12 | # django-cors-headers 13 | # django-debug-toolbar 14 | # djangorestframework 15 | django-cors-headers==3.7.0 16 | # via -r django_3_2.in 17 | django-debug-toolbar==3.2.1 18 | # via -r django_3_2.in 19 | django-debug-toolbar-force==0.1.8 20 | # via -r django_3_2.in 21 | django-elasticsearch-debug-toolbar==2.0.0 22 | # via -r django_3_2.in 23 | django-nine==0.2.4 24 | # via 25 | # django-debug-toolbar-force 26 | # django-ormex 27 | django-ormex==0.2.1 28 | # via -r django_3_2.in 29 | djangorestframework==3.12.4 30 | # via -r django_3_2.in 31 | pytz==2021.1 32 | # via django 33 | six==1.16.0 34 | # via 35 | # django-debug-toolbar-force 36 | # django-ormex 37 | sqlparse==0.4.1 38 | # via 39 | # django 40 | # django-debug-toolbar 41 | -------------------------------------------------------------------------------- /examples/requirements/code_style.in: -------------------------------------------------------------------------------- 1 | pylint 2 | pycodestyle 3 | -------------------------------------------------------------------------------- /examples/requirements/code_style.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile with python 3.9 3 | # To update, run: 4 | # 5 | # pip-compile code_style.in 6 | # 7 | astroid==2.6.5 8 | # via pylint 9 | isort==5.9.2 10 | # via pylint 11 | lazy-object-proxy==1.6.0 12 | # via astroid 13 | mccabe==0.6.1 14 | # via pylint 15 | pycodestyle==2.7.0 16 | # via -r code_style.in 17 | pylint==2.9.5 18 | # via -r code_style.in 19 | toml==0.10.2 20 | # via pylint 21 | wrapt==1.12.1 22 | # via astroid 23 | 24 | # The following packages are considered to be unsafe in a requirements file: 25 | # setuptools 26 | -------------------------------------------------------------------------------- /examples/requirements/common.in: -------------------------------------------------------------------------------- 1 | #-r elastic.txt 2 | 3 | python-memcached==1.58 4 | pytz 5 | six>=1.9 6 | Pillow 7 | -------------------------------------------------------------------------------- /examples/requirements/common.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile with python 3.9 3 | # To update, run: 4 | # 5 | # pip-compile common.in 6 | # 7 | pillow==8.3.1 8 | # via -r common.in 9 | python-memcached==1.58 10 | # via -r common.in 11 | pytz==2021.1 12 | # via -r common.in 13 | six==1.16.0 14 | # via 15 | # -r common.in 16 | # python-memcached 17 | -------------------------------------------------------------------------------- /examples/requirements/coreapi_coreschema.in: -------------------------------------------------------------------------------- 1 | coreapi 2 | coreschema 3 | -------------------------------------------------------------------------------- /examples/requirements/coreapi_coreschema.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile with python 3.9 3 | # To update, run: 4 | # 5 | # pip-compile coreapi_coreschema.in 6 | # 7 | certifi==2021.5.30 8 | # via requests 9 | charset-normalizer==2.0.3 10 | # via requests 11 | coreapi==2.3.3 12 | # via -r coreapi_coreschema.in 13 | coreschema==0.0.4 14 | # via 15 | # -r coreapi_coreschema.in 16 | # coreapi 17 | idna==3.2 18 | # via requests 19 | itypes==1.2.0 20 | # via coreapi 21 | jinja2==3.0.1 22 | # via coreschema 23 | markupsafe==2.0.1 24 | # via jinja2 25 | requests==2.26.0 26 | # via coreapi 27 | uritemplate==3.0.1 28 | # via coreapi 29 | urllib3==1.26.6 30 | # via requests 31 | -------------------------------------------------------------------------------- /examples/requirements/debug.in: -------------------------------------------------------------------------------- 1 | ipdb==0.8.1 2 | ipython==7.0.1 3 | ipython-genutils==0.1.0 4 | -------------------------------------------------------------------------------- /examples/requirements/debug.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile with python 3.9 3 | # To update, run: 4 | # 5 | # pip-compile debug.in 6 | # 7 | backcall==0.2.0 8 | # via ipython 9 | decorator==5.0.9 10 | # via ipython 11 | ipdb==0.8.1 12 | # via -r debug.in 13 | ipython==7.0.1 14 | # via 15 | # -r debug.in 16 | # ipdb 17 | ipython-genutils==0.1.0 18 | # via 19 | # -r debug.in 20 | # traitlets 21 | jedi==0.18.0 22 | # via ipython 23 | parso==0.8.2 24 | # via jedi 25 | pexpect==4.8.0 26 | # via ipython 27 | pickleshare==0.7.5 28 | # via ipython 29 | prompt-toolkit==2.0.10 30 | # via ipython 31 | ptyprocess==0.7.0 32 | # via pexpect 33 | pygments==2.9.0 34 | # via ipython 35 | simplegeneric==0.8.1 36 | # via ipython 37 | six==1.16.0 38 | # via prompt-toolkit 39 | traitlets==4.3 40 | # via ipython 41 | wcwidth==0.2.5 42 | # via prompt-toolkit 43 | 44 | # The following packages are considered to be unsafe in a requirements file: 45 | # setuptools 46 | -------------------------------------------------------------------------------- /examples/requirements/deployment.in: -------------------------------------------------------------------------------- 1 | twine 2 | pip-tools 3 | -------------------------------------------------------------------------------- /examples/requirements/deployment.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile with python 3.9 3 | # To update, run: 4 | # 5 | # pip-compile deployment.in 6 | # 7 | bleach==3.3.1 8 | # via readme-renderer 9 | certifi==2021.5.30 10 | # via requests 11 | cffi==1.14.6 12 | # via cryptography 13 | charset-normalizer==2.0.3 14 | # via requests 15 | click==8.0.1 16 | # via pip-tools 17 | colorama==0.4.4 18 | # via twine 19 | cryptography==3.4.7 20 | # via secretstorage 21 | docutils==0.17.1 22 | # via readme-renderer 23 | idna==3.2 24 | # via requests 25 | importlib-metadata==4.6.1 26 | # via 27 | # keyring 28 | # twine 29 | jeepney==0.7.0 30 | # via 31 | # keyring 32 | # secretstorage 33 | keyring==23.0.1 34 | # via twine 35 | packaging==21.0 36 | # via bleach 37 | pep517==0.11.0 38 | # via pip-tools 39 | pip-tools==6.2.0 40 | # via -r deployment.in 41 | pkginfo==1.7.1 42 | # via twine 43 | pycparser==2.20 44 | # via cffi 45 | pygments==2.9.0 46 | # via readme-renderer 47 | pyparsing==2.4.7 48 | # via packaging 49 | readme-renderer==29.0 50 | # via twine 51 | requests==2.26.0 52 | # via 53 | # requests-toolbelt 54 | # twine 55 | requests-toolbelt==0.9.1 56 | # via twine 57 | rfc3986==1.5.0 58 | # via twine 59 | secretstorage==3.3.1 60 | # via keyring 61 | six==1.16.0 62 | # via 63 | # bleach 64 | # readme-renderer 65 | tomli==1.1.0 66 | # via pep517 67 | tqdm==4.61.2 68 | # via twine 69 | twine==3.4.2 70 | # via -r deployment.in 71 | urllib3==1.26.6 72 | # via requests 73 | webencodings==0.5.1 74 | # via bleach 75 | wheel==0.36.2 76 | # via pip-tools 77 | zipp==3.5.0 78 | # via importlib-metadata 79 | 80 | # The following packages are considered to be unsafe in a requirements file: 81 | # pip 82 | # setuptools 83 | -------------------------------------------------------------------------------- /examples/requirements/dev.in: -------------------------------------------------------------------------------- 1 | -r base.in 2 | -r debug.in 3 | -r docs.in 4 | -r code_style.in 5 | -------------------------------------------------------------------------------- /examples/requirements/django_1_11.in: -------------------------------------------------------------------------------- 1 | -r common.in 2 | -r test.in 3 | 4 | Django>=1.11,<2.0 5 | django-cors-headers==2.4.0 6 | django-debug-toolbar==1.5 7 | django-debug-toolbar-force==0.1.3 8 | django-elasticsearch-debug-toolbar==1.2.0 9 | django-ormex>=0.2.1 10 | djangorestframework==3.9.3 11 | sqlparse==0.2.2 12 | -------------------------------------------------------------------------------- /examples/requirements/django_2_0.in: -------------------------------------------------------------------------------- 1 | -r common.in 2 | -r test.in 3 | 4 | Django>=2.0,<2.1 5 | django-cors-headers==2.4.0 6 | django-debug-toolbar>=1.6 7 | django-debug-toolbar-force>=0.1.3 8 | django-elasticsearch-debug-toolbar>=1.2.0 9 | django-ormex>=0.2.1 10 | djangorestframework==3.9.3 11 | sqlparse>=0.2.2 12 | -------------------------------------------------------------------------------- /examples/requirements/django_2_1.in: -------------------------------------------------------------------------------- 1 | -r common.in 2 | -r test.in 3 | 4 | Django>=2.1,<2.2 5 | django-cors-headers==2.4.0 6 | django-debug-toolbar>=1.9.1 7 | django-debug-toolbar-force>=0.1.3 8 | django-elasticsearch-debug-toolbar>=1.2.0 9 | django-ormex>=0.2.1 10 | djangorestframework==3.9.3 11 | sqlparse>=0.2.2 12 | -------------------------------------------------------------------------------- /examples/requirements/django_2_2.in: -------------------------------------------------------------------------------- 1 | -r common.in 2 | -r test.in 3 | 4 | Django>=2.2,<2.3 5 | django-cors-headers==2.5.2 6 | django-debug-toolbar==1.9.1 7 | django-debug-toolbar-force>=0.1.3 8 | django-elasticsearch-debug-toolbar>=1.2.0 9 | django-ormex>=0.2.1 10 | djangorestframework==3.9.3 11 | sqlparse>=0.2.2 12 | -------------------------------------------------------------------------------- /examples/requirements/django_2_2_and_elastic_6x.in: -------------------------------------------------------------------------------- 1 | -r django_2_2.in 2 | -r elastic_6x.in 3 | -------------------------------------------------------------------------------- /examples/requirements/django_2_2_and_elastic_7x.in: -------------------------------------------------------------------------------- 1 | -r django_2_2.in 2 | -r elastic_7x.in 3 | -------------------------------------------------------------------------------- /examples/requirements/django_3_1.in: -------------------------------------------------------------------------------- 1 | -r common.in 2 | -r test.in 3 | 4 | Django>=3.1,<3.2 5 | django-cors-headers==3.6.0 6 | django-debug-toolbar>=3.2 7 | django-debug-toolbar-force>=0.1.7 8 | django-elasticsearch-debug-toolbar>=2.0 9 | django-ormex>=0.2.1 10 | djangorestframework>=3.12.0,<3.13 11 | -------------------------------------------------------------------------------- /examples/requirements/django_3_1_and_elastic_6x.in: -------------------------------------------------------------------------------- 1 | -r django_3_1.in 2 | -r elastic_6x.in 3 | -------------------------------------------------------------------------------- /examples/requirements/django_3_1_and_elastic_7x.in: -------------------------------------------------------------------------------- 1 | -r django_3_1.in 2 | -r elastic_7x.in 3 | -------------------------------------------------------------------------------- /examples/requirements/django_3_2.in: -------------------------------------------------------------------------------- 1 | Django>=3.2,<3.3 2 | django-cors-headers==3.7.0 3 | django-debug-toolbar>=3.2 4 | django-debug-toolbar-force>=0.1.7 5 | django-elasticsearch-debug-toolbar>=2.0 6 | django-ormex>=0.2.1 7 | djangorestframework>=3.12.0,<3.13 8 | 9 | -------------------------------------------------------------------------------- /examples/requirements/django_3_2.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile with python 3.9 3 | # To update, run: 4 | # 5 | # pip-compile django_3_2.in 6 | # 7 | asgiref==3.4.1 8 | # via django 9 | django==3.2.5 10 | # via 11 | # -r django_3_2.in 12 | # django-cors-headers 13 | # django-debug-toolbar 14 | # djangorestframework 15 | django-cors-headers==3.7.0 16 | # via -r django_3_2.in 17 | django-debug-toolbar==3.2.1 18 | # via -r django_3_2.in 19 | django-debug-toolbar-force==0.1.8 20 | # via -r django_3_2.in 21 | django-elasticsearch-debug-toolbar==2.0.0 22 | # via -r django_3_2.in 23 | django-nine==0.2.4 24 | # via 25 | # django-debug-toolbar-force 26 | # django-ormex 27 | django-ormex==0.2.1 28 | # via -r django_3_2.in 29 | djangorestframework==3.12.4 30 | # via -r django_3_2.in 31 | pytz==2021.1 32 | # via django 33 | six==1.16.0 34 | # via 35 | # django-debug-toolbar-force 36 | # django-ormex 37 | sqlparse==0.4.1 38 | # via 39 | # django 40 | # django-debug-toolbar 41 | -------------------------------------------------------------------------------- /examples/requirements/django_3_2_and_elastic_6x.in: -------------------------------------------------------------------------------- 1 | -r django_3_2.in 2 | -r elastic_6x.in 3 | -------------------------------------------------------------------------------- /examples/requirements/django_3_2_and_elastic_6x.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile with python 3.9 3 | # To update, run: 4 | # 5 | # pip-compile django_3_2_and_elastic_6x.in 6 | # 7 | asgiref==3.4.1 8 | # via django 9 | django==3.2.5 10 | # via 11 | # -r django_3_2.in 12 | # django-cors-headers 13 | # django-debug-toolbar 14 | # django-nine 15 | # djangorestframework 16 | django-cors-headers==3.7.0 17 | # via -r django_3_2.in 18 | django-debug-toolbar==3.2.1 19 | # via -r django_3_2.in 20 | django-debug-toolbar-force==0.1.8 21 | # via -r django_3_2.in 22 | django-elasticsearch-debug-toolbar==2.0.0 23 | # via -r django_3_2.in 24 | https://github.com/django-es/django-elasticsearch-dsl/archive/dbbbfac01e4ba85c5e991fb1c0522404f170bdc0.zip 25 | # via -r elastic_6x.in 26 | django-nine==0.2.4 27 | # via 28 | # django-debug-toolbar-force 29 | # django-ormex 30 | django-ormex==0.2.1 31 | # via -r django_3_2.in 32 | djangorestframework==3.12.4 33 | # via -r django_3_2.in 34 | elasticsearch==6.3.0 35 | # via 36 | # -r elastic_6x.in 37 | # elasticsearch-dsl 38 | elasticsearch-dsl==6.4.0 39 | # via 40 | # -r elastic_6x.in 41 | # django-elasticsearch-dsl 42 | python-dateutil==2.8.2 43 | # via elasticsearch-dsl 44 | pytz==2021.1 45 | # via django 46 | six==1.16.0 47 | # via 48 | # django-debug-toolbar-force 49 | # django-elasticsearch-dsl 50 | # django-ormex 51 | # elasticsearch-dsl 52 | # python-dateutil 53 | sqlparse==0.4.1 54 | # via 55 | # django 56 | # django-debug-toolbar 57 | urllib3==1.26.6 58 | # via elasticsearch 59 | -------------------------------------------------------------------------------- /examples/requirements/django_3_2_and_elastic_7x.in: -------------------------------------------------------------------------------- 1 | -r django_3_2.in 2 | -r elastic_7x.in 3 | -------------------------------------------------------------------------------- /examples/requirements/django_3_2_and_elastic_7x.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile with python 3.9 3 | # To update, run: 4 | # 5 | # pip-compile django_3_2_and_elastic_7x.in 6 | # 7 | asgiref==3.4.1 8 | # via django 9 | certifi==2021.5.30 10 | # via elasticsearch 11 | django==3.2.5 12 | # via 13 | # -r django_3_2.in 14 | # django-cors-headers 15 | # django-debug-toolbar 16 | # django-nine 17 | # djangorestframework 18 | django-cors-headers==3.7.0 19 | # via -r django_3_2.in 20 | django-debug-toolbar==3.2.1 21 | # via -r django_3_2.in 22 | django-debug-toolbar-force==0.1.8 23 | # via -r django_3_2.in 24 | django-elasticsearch-debug-toolbar==2.0.0 25 | # via -r django_3_2.in 26 | django-elasticsearch-dsl==7.1.4 27 | # via -r elastic_7x.in 28 | django-nine==0.2.4 29 | # via 30 | # django-debug-toolbar-force 31 | # django-ormex 32 | django-ormex==0.2.1 33 | # via -r django_3_2.in 34 | djangorestframework==3.12.4 35 | # via -r django_3_2.in 36 | elasticsearch==7.10.1 37 | # via 38 | # -r elastic_7x.in 39 | # elasticsearch-dsl 40 | elasticsearch-dsl==7.3.0 41 | # via 42 | # -r elastic_7x.in 43 | # django-elasticsearch-dsl 44 | python-dateutil==2.8.2 45 | # via elasticsearch-dsl 46 | pytz==2021.1 47 | # via django 48 | six==1.16.0 49 | # via 50 | # django-debug-toolbar-force 51 | # django-elasticsearch-dsl 52 | # django-ormex 53 | # elasticsearch-dsl 54 | # python-dateutil 55 | sqlparse==0.4.1 56 | # via 57 | # django 58 | # django-debug-toolbar 59 | urllib3==1.26.6 60 | # via elasticsearch 61 | -------------------------------------------------------------------------------- /examples/requirements/docs.in: -------------------------------------------------------------------------------- 1 | #rst2pdf 2 | #rinohtype 3 | https://github.com/barseghyanartur/rinohtype/archive/0.3.1.zip 4 | sphinx 5 | matyan 6 | -------------------------------------------------------------------------------- /examples/requirements/documentation.in: -------------------------------------------------------------------------------- 1 | -r base.in 2 | -r docs.in 3 | elasticsearch<8.0.0 4 | django-elasticsearch-dsl-drf 5 | -------------------------------------------------------------------------------- /examples/requirements/elastic.in: -------------------------------------------------------------------------------- 1 | -r elastic_7x.in 2 | -------------------------------------------------------------------------------- /examples/requirements/elastic.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile with python 3.9 3 | # To update, run: 4 | # 5 | # pip-compile elastic.in 6 | # 7 | certifi==2021.5.30 8 | # via elasticsearch 9 | django-elasticsearch-dsl==7.1.4 10 | # via -r elastic_7x.in 11 | elasticsearch==7.10.1 12 | # via 13 | # -r elastic_7x.in 14 | # elasticsearch-dsl 15 | elasticsearch-dsl==7.3.0 16 | # via 17 | # -r elastic_7x.in 18 | # django-elasticsearch-dsl 19 | python-dateutil==2.8.2 20 | # via elasticsearch-dsl 21 | six==1.16.0 22 | # via 23 | # django-elasticsearch-dsl 24 | # elasticsearch-dsl 25 | # python-dateutil 26 | urllib3==1.26.6 27 | # via elasticsearch 28 | -------------------------------------------------------------------------------- /examples/requirements/elastic_2x.in: -------------------------------------------------------------------------------- 1 | elasticsearch==2.4.1 2 | elasticsearch-dsl==2.2.0 3 | django-elasticsearch-dsl==0.5.1 4 | -------------------------------------------------------------------------------- /examples/requirements/elastic_5x.in: -------------------------------------------------------------------------------- 1 | elasticsearch==5.4.0 2 | elasticsearch-dsl==5.3.0 3 | django-elasticsearch-dsl==0.5.1 -------------------------------------------------------------------------------- /examples/requirements/elastic_6x.in: -------------------------------------------------------------------------------- 1 | elasticsearch==6.3.0 2 | elasticsearch-dsl==6.4.0 3 | #django-elasticsearch-dsl==6.4.2 4 | # Pinned to the latest commit (as of 2021-02-02) of the 5 | # branch https://github.com/django-es/django-elasticsearch-dsl/tree/6.x 6 | https://github.com/django-es/django-elasticsearch-dsl/archive/dbbbfac01e4ba85c5e991fb1c0522404f170bdc0.zip 7 | -------------------------------------------------------------------------------- /examples/requirements/elastic_6x.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile with python 3.9 3 | # To update, run: 4 | # 5 | # pip-compile elastic_6x.in 6 | # 7 | https://github.com/django-es/django-elasticsearch-dsl/archive/dbbbfac01e4ba85c5e991fb1c0522404f170bdc0.zip 8 | # via -r elastic_6x.in 9 | elasticsearch==6.3.0 10 | # via 11 | # -r elastic_6x.in 12 | # elasticsearch-dsl 13 | elasticsearch-dsl==6.4.0 14 | # via 15 | # -r elastic_6x.in 16 | # django-elasticsearch-dsl 17 | python-dateutil==2.8.2 18 | # via elasticsearch-dsl 19 | six==1.16.0 20 | # via 21 | # django-elasticsearch-dsl 22 | # elasticsearch-dsl 23 | # python-dateutil 24 | urllib3==1.26.6 25 | # via elasticsearch 26 | -------------------------------------------------------------------------------- /examples/requirements/elastic_7x.in: -------------------------------------------------------------------------------- 1 | elasticsearch==7.10.1 #7.0.2 2 | elasticsearch-dsl==7.3.0 #7.0.0 3 | django-elasticsearch-dsl==7.1.4 4 | -------------------------------------------------------------------------------- /examples/requirements/elastic_7x.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile with python 3.9 3 | # To update, run: 4 | # 5 | # pip-compile elastic_7x.in 6 | # 7 | certifi==2021.5.30 8 | # via elasticsearch 9 | django-elasticsearch-dsl==7.1.4 10 | # via -r elastic_7x.in 11 | elasticsearch==7.10.1 12 | # via 13 | # -r elastic_7x.in 14 | # elasticsearch-dsl 15 | elasticsearch-dsl==7.3.0 16 | # via 17 | # -r elastic_7x.in 18 | # django-elasticsearch-dsl 19 | python-dateutil==2.8.2 20 | # via elasticsearch-dsl 21 | six==1.16.0 22 | # via 23 | # django-elasticsearch-dsl 24 | # elasticsearch-dsl 25 | # python-dateutil 26 | urllib3==1.26.6 27 | # via elasticsearch 28 | -------------------------------------------------------------------------------- /examples/requirements/elastic_docker.in: -------------------------------------------------------------------------------- 1 | elasticsearch==7.5.1 2 | elasticsearch-dsl==7.1.0 3 | django-elasticsearch-dsl==7.1.1 4 | -------------------------------------------------------------------------------- /examples/requirements/elastic_docker.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile with python 3.9 3 | # To update, run: 4 | # 5 | # pip-compile elastic_docker.in 6 | # 7 | django-elasticsearch-dsl==7.1.1 8 | # via -r elastic_docker.in 9 | elasticsearch==7.5.1 10 | # via 11 | # -r elastic_docker.in 12 | # elasticsearch-dsl 13 | elasticsearch-dsl==7.1.0 14 | # via 15 | # -r elastic_docker.in 16 | # django-elasticsearch-dsl 17 | python-dateutil==2.8.2 18 | # via elasticsearch-dsl 19 | six==1.16.0 20 | # via 21 | # django-elasticsearch-dsl 22 | # elasticsearch-dsl 23 | # python-dateutil 24 | urllib3==1.26.9 25 | # via elasticsearch 26 | -------------------------------------------------------------------------------- /examples/requirements/none.in: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /examples/requirements/schema.in: -------------------------------------------------------------------------------- 1 | drf-spectacular[sidecar] 2 | pyyaml 3 | -------------------------------------------------------------------------------- /examples/requirements/test.in: -------------------------------------------------------------------------------- 1 | Faker==8.1.4 2 | coverage>=4.5.4 3 | factory_boy==2.11.1 4 | mock 5 | py 6 | pytest-cov==2.12.0 7 | pytest-django==4.3.0 8 | pytest-ordering==0.6 9 | pytest-pythonpath 10 | pytest==6.2.4 11 | selenium==3.141.0 12 | tox==3.23.1 13 | -------------------------------------------------------------------------------- /examples/requirements/test.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile with python 3.9 3 | # To update, run: 4 | # 5 | # pip-compile test.in 6 | # 7 | attrs==21.2.0 8 | # via pytest 9 | backports.entry-points-selectable==1.1.0 10 | # via virtualenv 11 | coverage[toml]==5.5 12 | # via 13 | # -r test.in 14 | # pytest-cov 15 | distlib==0.3.2 16 | # via virtualenv 17 | factory_boy==2.11.1 18 | # via -r test.in 19 | faker==8.1.4 20 | # via 21 | # -r test.in 22 | # factory-boy 23 | filelock==3.0.12 24 | # via 25 | # tox 26 | # virtualenv 27 | iniconfig==1.1.1 28 | # via pytest 29 | mock==4.0.3 30 | # via -r test.in 31 | packaging==21.0 32 | # via 33 | # pytest 34 | # tox 35 | platformdirs==2.0.2 36 | # via virtualenv 37 | pluggy==0.13.1 38 | # via 39 | # pytest 40 | # tox 41 | py==1.10.0 42 | # via 43 | # -r test.in 44 | # pytest 45 | # tox 46 | pyparsing==2.4.7 47 | # via packaging 48 | pytest==6.2.4 49 | # via 50 | # -r test.in 51 | # pytest-cov 52 | # pytest-django 53 | # pytest-ordering 54 | # pytest-pythonpath 55 | pytest-cov==2.12.0 56 | # via -r test.in 57 | pytest-django==4.3.0 58 | # via -r test.in 59 | pytest-ordering==0.6 60 | # via -r test.in 61 | pytest-pythonpath==0.7.3 62 | # via -r test.in 63 | python-dateutil==2.8.2 64 | # via faker 65 | selenium==3.141.0 66 | # via -r test.in 67 | six==1.16.0 68 | # via 69 | # python-dateutil 70 | # tox 71 | # virtualenv 72 | text-unidecode==1.3 73 | # via faker 74 | toml==0.10.2 75 | # via 76 | # coverage 77 | # pytest 78 | # tox 79 | tox==3.23.1 80 | # via -r test.in 81 | urllib3==1.26.6 82 | # via selenium 83 | virtualenv==20.6.0 84 | # via tox 85 | -------------------------------------------------------------------------------- /examples/requirements/testing.in: -------------------------------------------------------------------------------- 1 | -r base.in 2 | -r test.in 3 | -------------------------------------------------------------------------------- /examples/simple/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/django-elasticsearch-dsl-drf/d83900f2c92b38b00423065795b146434c5a5bf7/examples/simple/__init__.py -------------------------------------------------------------------------------- /examples/simple/assets/README.rst: -------------------------------------------------------------------------------- 1 | assets 2 | ====== 3 | Assets for the site. Do not put here any other code that generic CSS, images 4 | and JavaScript files. 5 | -------------------------------------------------------------------------------- /examples/simple/assets/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/django-elasticsearch-dsl-drf/d83900f2c92b38b00423065795b146434c5a5bf7/examples/simple/assets/__init__.py -------------------------------------------------------------------------------- /examples/simple/assets/static/css/app.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/django-elasticsearch-dsl-drf/d83900f2c92b38b00423065795b146434c5a5bf7/examples/simple/assets/static/css/app.css -------------------------------------------------------------------------------- /examples/simple/assets/static/js/app.js: -------------------------------------------------------------------------------- 1 | $(document).foundation() 2 | -------------------------------------------------------------------------------- /examples/simple/books/README.rst: -------------------------------------------------------------------------------- 1 | books 2 | ===== 3 | Sample application. 4 | 5 | Most of the code taken from `official Django documentation 6 | `_. 7 | 8 | models 9 | ------ 10 | - Author 11 | - Book 12 | - Order 13 | - OrderLine 14 | - Publisher 15 | 16 | management commands 17 | ------------------- 18 | books_create_test_data 19 | ~~~~~~~~~~~~~~~~~~~~~~ 20 | Create project dummy data (dynamic fixtures). By default creates a 100 Book 21 | records. Accepts an optional --number parameter for customising the number 22 | of Book records created. 23 | 24 | **Create Book records** 25 | 26 | .. code-block:: sh 27 | 28 | ./manage.py books_create_test_data 29 | 30 | **Create 1000 Book records** 31 | 32 | .. code-block:: sh 33 | 34 | ./manage.py books_create_test_data --number=1000 35 | -------------------------------------------------------------------------------- /examples/simple/books/__init__.py: -------------------------------------------------------------------------------- 1 | default_app_config = 'books.apps.Config' 2 | -------------------------------------------------------------------------------- /examples/simple/books/apps.py: -------------------------------------------------------------------------------- 1 | try: 2 | from django.apps import AppConfig 3 | 4 | class Config(AppConfig): 5 | """Config.""" 6 | 7 | name = 'books' 8 | label = 'books' 9 | 10 | __all__ = ('Config',) 11 | 12 | except ImportError: 13 | pass 14 | -------------------------------------------------------------------------------- /examples/simple/books/constants.py: -------------------------------------------------------------------------------- 1 | BOOK_PUBLISHING_STATUS_PUBLISHED = 'published' 2 | BOOK_PUBLISHING_STATUS_NOT_PUBLISHED = 'not_published' 3 | BOOK_PUBLISHING_STATUS_IN_PROGRESS = 'in_progress' 4 | BOOK_PUBLISHING_STATUS_CANCELLED = 'cancelled' 5 | BOOK_PUBLISHING_STATUS_REJECTED = 'rejected' 6 | BOOK_PUBLISHING_STATUS_CHOICES = ( 7 | (BOOK_PUBLISHING_STATUS_PUBLISHED, "Published"), 8 | (BOOK_PUBLISHING_STATUS_NOT_PUBLISHED, "Not published"), 9 | (BOOK_PUBLISHING_STATUS_IN_PROGRESS, "In progress"), 10 | (BOOK_PUBLISHING_STATUS_CANCELLED, "Cancelled"), 11 | (BOOK_PUBLISHING_STATUS_REJECTED, "Rejected"), 12 | ) 13 | BOOK_PUBLISHING_STATUS_DEFAULT = BOOK_PUBLISHING_STATUS_PUBLISHED 14 | 15 | YES = 'yes' 16 | NO = 'no' 17 | 18 | LOCATION_CATEGORY_OFFICE = 'Office' 19 | LOCATION_CATEGORY_INDUSTRIAL = 'Industrial' 20 | LOCATION_CATEGORY_RETAIL = 'Retail' 21 | LOCATION_CATEGORY_LEISURE = 'Leisure' 22 | LOCATION_CATEGORY_CHOICES = ( 23 | (LOCATION_CATEGORY_OFFICE, LOCATION_CATEGORY_OFFICE), 24 | (LOCATION_CATEGORY_INDUSTRIAL, LOCATION_CATEGORY_INDUSTRIAL), 25 | (LOCATION_CATEGORY_RETAIL, LOCATION_CATEGORY_RETAIL), 26 | (LOCATION_CATEGORY_LEISURE, LOCATION_CATEGORY_LEISURE), 27 | ) 28 | -------------------------------------------------------------------------------- /examples/simple/books/management/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/django-elasticsearch-dsl-drf/d83900f2c92b38b00423065795b146434c5a5bf7/examples/simple/books/management/__init__.py -------------------------------------------------------------------------------- /examples/simple/books/management/commands/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/django-elasticsearch-dsl-drf/d83900f2c92b38b00423065795b146434c5a5bf7/examples/simple/books/management/commands/__init__.py -------------------------------------------------------------------------------- /examples/simple/books/migrations/0002_auto_20170223_1938.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals 3 | 4 | from django.db import migrations, models 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | dependencies = [ 10 | ('books', '0001_initial'), 11 | ] 12 | 13 | operations = [ 14 | migrations.AlterField( 15 | model_name='book', 16 | name='isbn', 17 | field=models.CharField(unique=True, max_length=100), 18 | ), 19 | ] 20 | -------------------------------------------------------------------------------- /examples/simple/books/migrations/0003_book_pages.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals 3 | 4 | from django.db import migrations, models 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | dependencies = [ 10 | ('books', '0002_auto_20170223_1938'), 11 | ] 12 | 13 | operations = [ 14 | migrations.AddField( 15 | model_name='book', 16 | name='pages', 17 | field=models.IntegerField(default=200), 18 | ), 19 | ] 20 | -------------------------------------------------------------------------------- /examples/simple/books/migrations/0004_auto_20170322_2001.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals 3 | 4 | from django.db import migrations, models 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | dependencies = [ 10 | ('books', '0003_book_pages'), 11 | ] 12 | 13 | operations = [ 14 | migrations.AddField( 15 | model_name='book', 16 | name='stock_count', 17 | field=models.PositiveIntegerField(default=30), 18 | ), 19 | migrations.AlterField( 20 | model_name='book', 21 | name='authors', 22 | field=models.ManyToManyField(related_name='books', to='books.Author'), 23 | ), 24 | migrations.AlterField( 25 | model_name='book', 26 | name='pages', 27 | field=models.PositiveIntegerField(default=200), 28 | ), 29 | migrations.AlterField( 30 | model_name='book', 31 | name='publisher', 32 | field=models.ForeignKey(related_name='books', to='books.Publisher', on_delete=models.CASCADE), 33 | ), 34 | migrations.AlterField( 35 | model_name='orderline', 36 | name='book', 37 | field=models.ForeignKey(related_name='order_lines', to='books.Book', on_delete=models.CASCADE), 38 | ), 39 | ] 40 | -------------------------------------------------------------------------------- /examples/simple/books/migrations/0005_auto_20170518_1553.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by Django 1.10.7 on 2017-05-18 20:53 3 | from __future__ import unicode_literals 4 | 5 | from django.db import migrations, models 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | ('books', '0004_auto_20170322_2001'), 12 | ] 13 | 14 | operations = [ 15 | migrations.AlterModelOptions( 16 | name='author', 17 | options={'ordering': ['id']}, 18 | ), 19 | migrations.AlterModelOptions( 20 | name='publisher', 21 | options={'ordering': ['id']}, 22 | ), 23 | migrations.AlterField( 24 | model_name='author', 25 | name='headshot', 26 | field=models.ImageField(blank=True, null=True, upload_to='authors'), 27 | ), 28 | ] 29 | -------------------------------------------------------------------------------- /examples/simple/books/migrations/0006_auto_20170619_0428.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by Django 1.10.5 on 2017-06-19 09:28 3 | from __future__ import unicode_literals 4 | 5 | from django.db import migrations, models 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | ('books', '0005_auto_20170518_1553'), 12 | ] 13 | 14 | operations = [ 15 | migrations.CreateModel( 16 | name='Tag', 17 | fields=[ 18 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 19 | ('title', models.CharField(max_length=255, unique=True)), 20 | ], 21 | options={ 22 | 'verbose_name_plural': 'Tags', 23 | 'verbose_name': 'Tag', 24 | }, 25 | ), 26 | migrations.AddField( 27 | model_name='book', 28 | name='summary', 29 | field=models.TextField(blank=True, null=True), 30 | ), 31 | migrations.AddField( 32 | model_name='book', 33 | name='tags', 34 | field=models.ManyToManyField(blank=True, related_name='books', to='books.Tag'), 35 | ), 36 | ] 37 | -------------------------------------------------------------------------------- /examples/simple/books/migrations/0007_book_description.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by Django 1.10.5 on 2017-06-19 10:05 3 | from __future__ import unicode_literals 4 | 5 | from django.db import migrations, models 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | ('books', '0006_auto_20170619_0428'), 12 | ] 13 | 14 | operations = [ 15 | migrations.AddField( 16 | model_name='book', 17 | name='description', 18 | field=models.TextField(blank=True, null=True), 19 | ), 20 | ] 21 | -------------------------------------------------------------------------------- /examples/simple/books/migrations/0008_book_state.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by Django 1.10.5 on 2017-06-19 12:02 3 | from __future__ import unicode_literals 4 | 5 | from django.db import migrations, models 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | ('books', '0007_book_description'), 12 | ] 13 | 14 | operations = [ 15 | migrations.AddField( 16 | model_name='book', 17 | name='state', 18 | field=models.CharField(choices=[('pulished', 'Published'), ('not_published', 'Not published'), ('in_progress', 'In progress'), ('canelled', 'Cancelled'), ('rejected', 'Rejected')], default='pulished', max_length=100), 19 | ), 20 | ] 21 | -------------------------------------------------------------------------------- /examples/simple/books/migrations/0009_auto_20170626_1331.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by Django 1.11.2 on 2017-06-26 18:31 3 | from __future__ import unicode_literals 4 | 5 | from django.db import migrations, models 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | ('books', '0008_book_state'), 12 | ] 13 | 14 | operations = [ 15 | migrations.AddField( 16 | model_name='publisher', 17 | name='info', 18 | field=models.TextField(blank=True, null=True), 19 | ), 20 | migrations.AlterField( 21 | model_name='book', 22 | name='state', 23 | field=models.CharField(choices=[('published', 'Published'), ('not_published', 'Not published'), ('in_progress', 'In progress'), ('cancelled', 'Cancelled'), ('rejected', 'Rejected')], default='published', max_length=100), 24 | ), 25 | ] 26 | -------------------------------------------------------------------------------- /examples/simple/books/migrations/0010_auto_20170823_1542.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by Django 1.11.4 on 2017-08-23 20:42 3 | from __future__ import unicode_literals 4 | 5 | from django.db import migrations, models 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | ('books', '0009_auto_20170626_1331'), 12 | ] 13 | 14 | operations = [ 15 | migrations.AddField( 16 | model_name='author', 17 | name='biography', 18 | field=models.TextField(blank=True, null=True), 19 | ), 20 | migrations.AddField( 21 | model_name='author', 22 | name='birth_date', 23 | field=models.DateField(blank=True, null=True), 24 | ), 25 | migrations.AddField( 26 | model_name='author', 27 | name='phone_number', 28 | field=models.CharField(blank=True, max_length=200, null=True), 29 | ), 30 | migrations.AddField( 31 | model_name='author', 32 | name='website', 33 | field=models.URLField(blank=True, null=True), 34 | ), 35 | ] 36 | -------------------------------------------------------------------------------- /examples/simple/books/migrations/0011_auto_20170920_1607.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by Django 1.11.5 on 2017-09-20 21:07 3 | from __future__ import unicode_literals 4 | 5 | from django.db import migrations, models 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | ('books', '0010_auto_20170823_1542'), 12 | ] 13 | 14 | operations = [ 15 | migrations.AddField( 16 | model_name='book', 17 | name='lat', 18 | field=models.DecimalField(blank=True, decimal_places=15, max_digits=19, null=True), 19 | ), 20 | migrations.AddField( 21 | model_name='book', 22 | name='lon', 23 | field=models.DecimalField(blank=True, decimal_places=15, max_digits=19, null=True), 24 | ), 25 | ] 26 | -------------------------------------------------------------------------------- /examples/simple/books/migrations/0012_auto_20170921_1540.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by Django 1.11.4 on 2017-09-21 20:40 3 | from __future__ import unicode_literals 4 | 5 | from django.db import migrations, models 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | ('books', '0011_auto_20170920_1607'), 12 | ] 13 | 14 | operations = [ 15 | migrations.RemoveField( 16 | model_name='book', 17 | name='lat', 18 | ), 19 | migrations.RemoveField( 20 | model_name='book', 21 | name='lon', 22 | ), 23 | migrations.AddField( 24 | model_name='publisher', 25 | name='latitude', 26 | field=models.DecimalField(blank=True, decimal_places=15, default=0, max_digits=19, null=True), 27 | ), 28 | migrations.AddField( 29 | model_name='publisher', 30 | name='longitude', 31 | field=models.DecimalField(blank=True, decimal_places=15, default=0, max_digits=19, null=True), 32 | ), 33 | ] 34 | -------------------------------------------------------------------------------- /examples/simple/books/migrations/0014_auto_20171003_1434.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by Django 1.11.4 on 2017-10-03 19:34 3 | from __future__ import unicode_literals 4 | 5 | from django.db import migrations, models 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | ('books', '0013_auto_20171003_1430'), 12 | ] 13 | 14 | operations = [ 15 | migrations.AddField( 16 | model_name='city', 17 | name='info', 18 | field=models.TextField(blank=True, null=True), 19 | ), 20 | migrations.AddField( 21 | model_name='country', 22 | name='info', 23 | field=models.TextField(blank=True, null=True), 24 | ), 25 | ] 26 | -------------------------------------------------------------------------------- /examples/simple/books/migrations/0015_auto_20180622_1617.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by Django 1.10.8 on 2018-06-22 21:17 3 | from __future__ import unicode_literals 4 | 5 | from django.db import migrations, models 6 | import django.db.models.deletion 7 | 8 | 9 | class Migration(migrations.Migration): 10 | 11 | dependencies = [ 12 | ('books', '0014_auto_20171003_1434'), 13 | ] 14 | 15 | operations = [ 16 | migrations.CreateModel( 17 | name='Continent', 18 | fields=[ 19 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 20 | ('name', models.CharField(max_length=255)), 21 | ('info', models.TextField(blank=True, null=True)), 22 | ('latitude', models.DecimalField(blank=True, decimal_places=15, default=0, max_digits=19, null=True)), 23 | ('longitude', models.DecimalField(blank=True, decimal_places=15, default=0, max_digits=19, null=True)), 24 | ], 25 | options={ 26 | 'ordering': ['id'], 27 | }, 28 | ), 29 | migrations.AddField( 30 | model_name='country', 31 | name='continent', 32 | field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='books.Continent'), 33 | preserve_default=False, 34 | ), 35 | ] 36 | -------------------------------------------------------------------------------- /examples/simple/books/migrations/0016_book_created.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by Django 1.11.16 on 2018-11-23 22:49 3 | from __future__ import unicode_literals 4 | 5 | from django.db import migrations, models 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | ('books', '0015_auto_20180622_1617'), 12 | ] 13 | 14 | operations = [ 15 | migrations.AddField( 16 | model_name='book', 17 | name='created', 18 | field=models.DateTimeField(auto_now_add=True, null=True), 19 | ), 20 | ] 21 | -------------------------------------------------------------------------------- /examples/simple/books/migrations/0017_location.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by Django 1.11.16 on 2019-04-03 20:27 3 | from __future__ import unicode_literals 4 | 5 | from django.db import migrations, models 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | ('books', '0016_book_created'), 12 | ] 13 | 14 | operations = [ 15 | migrations.CreateModel( 16 | name='Location', 17 | fields=[ 18 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 19 | ('group', models.CharField(max_length=255)), 20 | ('occupation_status', models.BooleanField()), 21 | ('postcode', models.CharField(max_length=50)), 22 | ('address_no', models.CharField(max_length=255)), 23 | ('address_street', models.CharField(max_length=255)), 24 | ('address_town', models.CharField(max_length=255)), 25 | ('authority_name', models.CharField(max_length=255)), 26 | ('slug', models.CharField(max_length=255)), 27 | ('floor_area', models.FloatField()), 28 | ('employee_count', models.FloatField()), 29 | ('rental_valuation', models.FloatField()), 30 | ('revenue', models.FloatField()), 31 | ('latitude', models.DecimalField(blank=True, decimal_places=15, default=0, max_digits=19, null=True)), 32 | ('longitude', models.DecimalField(blank=True, decimal_places=15, default=0, max_digits=19, null=True)), 33 | ], 34 | options={ 35 | 'ordering': ['id'], 36 | }, 37 | ), 38 | ] 39 | -------------------------------------------------------------------------------- /examples/simple/books/migrations/0018_auto_20200916_1549.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.1 on 2020-09-16 20:49 2 | 3 | from django.db import migrations, models 4 | import django.db.models.deletion 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | dependencies = [ 10 | ('books', '0017_location'), 11 | ] 12 | 13 | operations = [ 14 | migrations.CreateModel( 15 | name='Galaxy', 16 | fields=[ 17 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 18 | ('name', models.CharField(max_length=255)), 19 | ], 20 | options={ 21 | 'ordering': ['id'], 22 | }, 23 | ), 24 | migrations.AlterField( 25 | model_name='location', 26 | name='group', 27 | field=models.CharField(choices=[('Office', 'Office'), ('Industrial', 'Industrial'), ('Retail', 'Retail'), ('Leisure', 'Leisure')], max_length=255), 28 | ), 29 | migrations.CreateModel( 30 | name='Planet', 31 | fields=[ 32 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 33 | ('name', models.CharField(max_length=255)), 34 | ('galaxy', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='books.galaxy')), 35 | ], 36 | options={ 37 | 'ordering': ['id'], 38 | }, 39 | ), 40 | migrations.AddField( 41 | model_name='address', 42 | name='planet', 43 | field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='books.planet'), 44 | ), 45 | ] 46 | -------------------------------------------------------------------------------- /examples/simple/books/migrations/0018_auto_20210203_1549.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.6 on 2021-02-03 21:49 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('books', '0017_location'), 10 | ] 11 | 12 | operations = [ 13 | migrations.CreateModel( 14 | name='Journal', 15 | fields=[ 16 | ('isbn', models.CharField(max_length=100, primary_key=True, serialize=False)), 17 | ('title', models.CharField(max_length=100)), 18 | ('description', models.TextField(blank=True, null=True)), 19 | ('summary', models.TextField(blank=True, null=True)), 20 | ('publication_date', models.DateField()), 21 | ('price', models.DecimalField(decimal_places=2, max_digits=10)), 22 | ('pages', models.PositiveIntegerField(default=200)), 23 | ('stock_count', models.PositiveIntegerField(default=30)), 24 | ('created', models.DateTimeField(auto_now_add=True, null=True)), 25 | ], 26 | options={ 27 | 'ordering': ['isbn'], 28 | }, 29 | ), 30 | migrations.AlterField( 31 | model_name='location', 32 | name='group', 33 | field=models.CharField(choices=[('Office', 'Office'), ('Industrial', 'Industrial'), ('Retail', 'Retail'), ('Leisure', 'Leisure')], max_length=255), 34 | ), 35 | ] 36 | -------------------------------------------------------------------------------- /examples/simple/books/migrations/0019_merge_20210219_1534.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.6 on 2021-02-19 21:34 2 | 3 | from django.db import migrations 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('books', '0018_auto_20210203_1549'), 10 | ('books', '0018_auto_20200916_1549'), 11 | ] 12 | 13 | operations = [ 14 | ] 15 | -------------------------------------------------------------------------------- /examples/simple/books/migrations/0020_order_finished.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.6 on 2021-03-25 22:10 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('books', '0019_merge_20210219_1534'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='order', 15 | name='finished', 16 | field=models.BooleanField(default=False), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /examples/simple/books/migrations/0021_city_capital.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.6 on 2021-03-25 22:25 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('books', '0020_order_finished'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='city', 15 | name='capital', 16 | field=models.BooleanField(default=False), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /examples/simple/books/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/django-elasticsearch-dsl-drf/d83900f2c92b38b00423065795b146434c5a5bf7/examples/simple/books/migrations/__init__.py -------------------------------------------------------------------------------- /examples/simple/books/mixins.py: -------------------------------------------------------------------------------- 1 | from django.http import JsonResponse 2 | 3 | __all__ = ('JSONResponseMixin',) 4 | 5 | 6 | class JSONResponseMixin(object): 7 | """A mixin that can be used to render a JSON response.""" 8 | 9 | def render_to_json_response(self, context, **response_kwargs): 10 | """Return a JSON response, transforming 'context' for the payload.""" 11 | return JsonResponse( 12 | self.get_data(context), 13 | **response_kwargs 14 | ) 15 | 16 | def get_data(self, context): 17 | """Return an object to be serialized as JSON by json.dumps().""" 18 | # Note: This is *EXTREMELY* naive; in reality, you'll need 19 | # to do much more complex handling to ensure that arbitrary 20 | # objects -- such as Django model instances or querysets 21 | # -- can be serialized as JSON. 22 | return context 23 | -------------------------------------------------------------------------------- /examples/simple/books/models/__init__.py: -------------------------------------------------------------------------------- 1 | from .address import Address 2 | from .author import Author 3 | from .book import Book 4 | from .city import City 5 | from .continent import Continent 6 | from .country import Country 7 | from .galaxy import Galaxy 8 | from .journal import Journal 9 | from .location import Location 10 | from .order import Order 11 | from .order_line import OrderLine 12 | from .planet import Planet 13 | from .publisher import Publisher 14 | from .tag import Tag 15 | 16 | __all__ = ( 17 | 'Address', 18 | 'Author', 19 | 'Book', 20 | 'City', 21 | 'Continent', 22 | 'Country', 23 | 'Galaxy', 24 | 'Journal', 25 | 'Location', 26 | 'Order', 27 | 'OrderLine', 28 | 'Planet', 29 | 'Publisher', 30 | 'Tag', 31 | ) 32 | -------------------------------------------------------------------------------- /examples/simple/books/models/author.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | __all__ = ('Author',) 4 | 5 | 6 | class Author(models.Model): 7 | """Author.""" 8 | 9 | salutation = models.CharField(max_length=10) 10 | name = models.CharField(max_length=200) 11 | email = models.EmailField() 12 | headshot = models.ImageField(upload_to='authors', null=True, blank=True) 13 | birth_date = models.DateField(null=True, blank=True) 14 | biography = models.TextField(null=True, blank=True) 15 | phone_number = models.CharField(max_length=200, null=True, blank=True) 16 | website = models.URLField(null=True, blank=True) 17 | 18 | class Meta: 19 | """Meta options.""" 20 | 21 | ordering = ["id"] 22 | 23 | def __str__(self): 24 | return self.name 25 | 26 | def headshot_indexing(self): 27 | """Headshot for indexing. 28 | 29 | Used in Elasticsearch indexing. 30 | """ 31 | if self.headshot: 32 | return self.headshot.url 33 | -------------------------------------------------------------------------------- /examples/simple/books/models/continent.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | 3 | from django.db import models 4 | 5 | __all__ = ('Continent',) 6 | 7 | 8 | class Continent(models.Model): 9 | """Continent.""" 10 | 11 | name = models.CharField(max_length=255) 12 | info = models.TextField(null=True, blank=True) 13 | latitude = models.DecimalField( 14 | null=True, 15 | blank=True, 16 | decimal_places=15, 17 | max_digits=19, 18 | default=0 19 | ) 20 | longitude = models.DecimalField( 21 | null=True, 22 | blank=True, 23 | decimal_places=15, 24 | max_digits=19, 25 | default=0 26 | ) 27 | 28 | class Meta: 29 | """Meta options.""" 30 | 31 | ordering = ["id"] 32 | 33 | def __str__(self): 34 | return self.name 35 | 36 | @property 37 | def location_field_indexing(self): 38 | """Location for indexing. 39 | 40 | Used in Elasticsearch indexing/tests of `geo_distance` native filter. 41 | """ 42 | return { 43 | 'lat': self.latitude, 44 | 'lon': self.longitude, 45 | } 46 | -------------------------------------------------------------------------------- /examples/simple/books/models/country.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | 3 | from django.db import models 4 | 5 | __all__ = ('Country',) 6 | 7 | 8 | class Country(models.Model): 9 | """Country.""" 10 | 11 | name = models.CharField(max_length=255) 12 | info = models.TextField(null=True, blank=True) 13 | continent = models.ForeignKey( 14 | 'books.Continent', 15 | on_delete=models.CASCADE 16 | ) 17 | latitude = models.DecimalField( 18 | null=True, 19 | blank=True, 20 | decimal_places=15, 21 | max_digits=19, 22 | default=0 23 | ) 24 | longitude = models.DecimalField( 25 | null=True, 26 | blank=True, 27 | decimal_places=15, 28 | max_digits=19, 29 | default=0 30 | ) 31 | 32 | class Meta: 33 | """Meta options.""" 34 | 35 | ordering = ["id"] 36 | 37 | def __str__(self): 38 | return self.name 39 | 40 | @property 41 | def location_field_indexing(self): 42 | """Location for indexing. 43 | 44 | Used in Elasticsearch indexing/tests of `geo_distance` native filter. 45 | """ 46 | return { 47 | 'lat': self.latitude, 48 | 'lon': self.longitude, 49 | } 50 | -------------------------------------------------------------------------------- /examples/simple/books/models/galaxy.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | 3 | from django.db import models 4 | 5 | __all__ = ('Galaxy',) 6 | 7 | 8 | class Galaxy(models.Model): 9 | """Galaxy.""" 10 | 11 | name = models.CharField(max_length=255) 12 | 13 | class Meta: 14 | """Meta options.""" 15 | 16 | ordering = ["id"] 17 | 18 | def __str__(self): 19 | return self.name 20 | -------------------------------------------------------------------------------- /examples/simple/books/models/journal.py: -------------------------------------------------------------------------------- 1 | from django.conf import settings 2 | from django.db import models 3 | 4 | __all__ = ('Journal',) 5 | 6 | 7 | class Journal(models.Model): 8 | """Journal.""" 9 | 10 | isbn = models.CharField(max_length=100, primary_key=True) 11 | title = models.CharField(max_length=100) 12 | description = models.TextField(null=True, blank=True) 13 | summary = models.TextField(null=True, blank=True) 14 | publication_date = models.DateField() 15 | price = models.DecimalField(max_digits=10, decimal_places=2) 16 | pages = models.PositiveIntegerField(default=200) 17 | stock_count = models.PositiveIntegerField(default=30) 18 | created = models.DateTimeField(auto_now_add=True, null=True, blank=True) 19 | 20 | class Meta: 21 | """Meta options.""" 22 | 23 | ordering = ["isbn"] 24 | 25 | def __str__(self): 26 | return self.title 27 | 28 | @property 29 | def created_indexing(self): 30 | return self.created.strftime(settings.ELASTICSEARCH_DATETIME_FORMAT) 31 | -------------------------------------------------------------------------------- /examples/simple/books/models/order.py: -------------------------------------------------------------------------------- 1 | from django.conf import settings 2 | from django.db import models 3 | from django.utils.translation import gettext_lazy as _ 4 | 5 | __all__ = ('Order',) 6 | 7 | 8 | class Order(models.Model): 9 | """Order.""" 10 | 11 | owner = models.ForeignKey( 12 | settings.AUTH_USER_MODEL, 13 | on_delete=models.CASCADE 14 | ) 15 | lines = models.ManyToManyField('books.OrderLine', blank=True) 16 | finished = models.BooleanField(default=False) 17 | created = models.DateField(auto_now_add=True) 18 | updated = models.DateField(auto_now=True) 19 | 20 | class Meta: 21 | """Meta options.""" 22 | 23 | ordering = ["-created"] 24 | 25 | def __str__(self): 26 | return _('Order') 27 | 28 | @property 29 | def created_indexing(self): 30 | return self.created.strftime(settings.ELASTICSEARCH_DATETIME_FORMAT) 31 | 32 | @property 33 | def updated_indexing(self): 34 | return self.updated.strftime(settings.ELASTICSEARCH_DATETIME_FORMAT) 35 | -------------------------------------------------------------------------------- /examples/simple/books/models/order_line.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | 3 | from django.db import models 4 | 5 | __all__ = ('OrderLine',) 6 | 7 | 8 | class OrderLine(models.Model): 9 | """Order line.""" 10 | 11 | book = models.ForeignKey( 12 | 'books.Book', 13 | related_name='order_lines', 14 | on_delete=models.CASCADE 15 | ) 16 | 17 | class Meta: 18 | """Meta options.""" 19 | 20 | ordering = ["order__created"] 21 | 22 | def __str__(self): 23 | return '{}'.format(self.book.isbn) 24 | -------------------------------------------------------------------------------- /examples/simple/books/models/planet.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | 3 | from django.db import models 4 | 5 | __all__ = ('Planet',) 6 | 7 | 8 | class Planet(models.Model): 9 | """Planet.""" 10 | 11 | name = models.CharField(max_length=255) 12 | galaxy = models.ForeignKey('books.Galaxy', on_delete=models.CASCADE) 13 | 14 | class Meta: 15 | """Meta options.""" 16 | 17 | ordering = ["id"] 18 | 19 | def __str__(self): 20 | return self.name 21 | -------------------------------------------------------------------------------- /examples/simple/books/models/tag.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.utils.translation import gettext_lazy as _ 3 | 4 | __all__ = ('Tag',) 5 | 6 | 7 | class Tag(models.Model): 8 | """Simple tag model.""" 9 | 10 | title = models.CharField(max_length=255, unique=True) 11 | 12 | class Meta: 13 | """Meta options.""" 14 | 15 | verbose_name = _("Tag") 16 | verbose_name_plural = _("Tags") 17 | 18 | def __str__(self): 19 | return self.title 20 | -------------------------------------------------------------------------------- /examples/simple/books/templates/books/add_authors_to_book.html: -------------------------------------------------------------------------------- 1 | {% extends "books/book_list.html" %} 2 | {% block meta-title %}Add authors to a book{% endblock %} 3 | 4 | {% block nav-menu-items %} 5 | {% with True as books_add_authors_to_book_is_active %} 6 | {% include "snippets/menu_items.html" %} 7 | {% endwith %} 8 | {% endblock nav-menu-items %} 9 | 10 | {% block main-content %} 11 |

Books

12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | {% for book in object_list %} 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | {% endfor %} 31 |
BookAuthorsPublisherNumber of pagesPrice
{{ book.title }}{% for author in book_authors %}{{ author.name }},{% endfor %}{{ book.publisher.name }}{{ book.pages }}{{ book.price }}
32 | {% endblock %} 33 | {% block sidebar-content %}{% endblock sidebar-content %} 34 | -------------------------------------------------------------------------------- /examples/simple/books/templates/books/author_list.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% block meta-title %}Authors{% endblock %} 3 | 4 | {% block nav-menu-items %} 5 | {% with True as books_authors_is_active %} 6 | {% include "snippets/menu_items.html" %} 7 | {% endwith %} 8 | {% endblock nav-menu-items %} 9 | 10 | {% block main-content %} 11 |

Authors

12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | {% for author in object_list %} 21 | 22 | 23 | 24 | 25 | 26 | {% endfor %} 27 |
SalutationNameE-mail
{{ author.salutation }}{{ author.name }}{{ author.email }}
28 | {% endblock %} 29 | {% block sidebar-content %}{% endblock sidebar-content %} 30 | -------------------------------------------------------------------------------- /examples/simple/books/templates/books/author_list_values.html: -------------------------------------------------------------------------------- 1 | {% extends "books/author_list.html" %} 2 | {% block meta-title %}Authors (values){% endblock %} 3 | 4 | {% block nav-menu-items %} 5 | {% with True as books_authors_values_is_active %} 6 | {% include "snippets/menu_items.html" %} 7 | {% endwith %} 8 | {% endblock nav-menu-items %} 9 | -------------------------------------------------------------------------------- /examples/simple/books/templates/books/book_list.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% block meta-title %}Books{% endblock %} 3 | 4 | {% block nav-menu-items %} 5 | {% with True as books_books_is_active %} 6 | {% include "snippets/menu_items.html" %} 7 | {% endwith %} 8 | {% endblock nav-menu-items %} 9 | 10 | {% block main-content %} 11 |

Books

12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | {% for book in object_list %} 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | {% endfor %} 31 |
BookAuthorsPublisherNumber of pagesPrice
{{ book.title }}{% for author in book.authors.all %}{{ author.name }}{% if not forloop.last %}, {% endif %}{% endfor %}{{ book.publisher.name }}{{ book.pages }}{{ book.price }}
32 | {% endblock %} 33 | {% block sidebar-content %}{% endblock sidebar-content %} 34 | -------------------------------------------------------------------------------- /examples/simple/books/templates/books/book_list_values.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% block meta-title %}Books (values){% endblock %} 3 | 4 | {% block nav-menu-items %} 5 | {% with True as books_books_values_is_active %} 6 | {% include "snippets/menu_items.html" %} 7 | {% endwith %} 8 | {% endblock nav-menu-items %} 9 | 10 | {% block main-content %} 11 |

Books

12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | {% for book in object_list %} 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | {% endfor %} 31 |
BookAuthorsPublisherNumber of pagesPrice
{{ book.title }}{{ book.authors__name}}{{ book.publisher__name }}{{ book.pages }}{{ book.price }}
32 | {% endblock %} 33 | {% block sidebar-content %}{% endblock sidebar-content %} 34 | -------------------------------------------------------------------------------- /examples/simple/books/templates/books/book_list_with_counts.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% block meta-title %}Books (with counts){% endblock %} 3 | 4 | {% block nav-menu-items %} 5 | {% with True as books_books_with_counts_is_active %} 6 | {% include "snippets/menu_items.html" %} 7 | {% endwith %} 8 | {% endblock nav-menu-items %} 9 | 10 | {% block main-content %} 11 |

Books

12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | {% for book in object_list %} 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | {% endfor %} 33 |
BookAuthorsPublisherNumber of pagesPricePrice per page
{{ book.title }}{% for author in book.authors.all %}{{ author.name }},{% endfor %}{{ book.publisher.name }}{{ book.pages }}{{ book.price }}{{ book.price_per_page }}
34 | {% endblock %} 35 | {% block sidebar-content %}{% endblock sidebar-content %} 36 | -------------------------------------------------------------------------------- /examples/simple/books/templates/books/create_authors.html: -------------------------------------------------------------------------------- 1 | {% extends "books/author_list.html" %} 2 | {% block meta-title %}Create authors{% endblock %} 3 | 4 | {% block nav-menu-items %} 5 | {% with True as books_create_authors_is_active %} 6 | {% include "snippets/menu_items.html" %} 7 | {% endwith %} 8 | {% endblock nav-menu-items %} 9 | -------------------------------------------------------------------------------- /examples/simple/books/templates/books/index.html: -------------------------------------------------------------------------------- 1 | {% extends "home.html" %} 2 | {% block meta-title %}Index{% endblock %} 3 | -------------------------------------------------------------------------------- /examples/simple/books/templates/books/publisher_ids.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% block meta-title %}Publisher IDs{% endblock %} 3 | 4 | {% block nav-menu-items %} 5 | {% with True as books_publisher_ids_is_active %} 6 | {% include "snippets/menu_items.html" %} 7 | {% endwith %} 8 | {% endblock nav-menu-items %} 9 | 10 | {% block main-content %} 11 |

Publisher IDs

12 | 13 | 14 | 15 | 16 | 17 | 18 | {% for publisher_id in object_list %} 19 | 20 | 21 | 22 | {% endfor %} 23 |
Publisher ID
{{ publisher_id }}
24 | {% endblock %} 25 | {% block sidebar-content %}{% endblock sidebar-content %} 26 | -------------------------------------------------------------------------------- /examples/simple/books/templates/books/publisher_list.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% block meta-title %}Publishers{% endblock %} 3 | 4 | {% block nav-menu-items %} 5 | {% with True as books_publishers_is_active %} 6 | {% include "snippets/menu_items.html" %} 7 | {% endwith %} 8 | {% endblock nav-menu-items %} 9 | 10 | {% block main-content %} 11 |

Publishers

12 | 13 | 14 | 15 | 16 | 17 | 18 | {% for publisher in object_list %} 19 | 20 | 21 | 22 | {% endfor %} 23 |
Name
{{ publisher }}
24 | {% endblock %} 25 | {% block sidebar-content %}{% endblock sidebar-content %} 26 | -------------------------------------------------------------------------------- /examples/simple/books/templates/books/update_books.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% block meta-title %}Update books{% endblock %} 3 | 4 | {% block nav-menu-items %} 5 | {% with True as books_update_books_is_active %} 6 | {% include "snippets/menu_items.html" %} 7 | {% endwith %} 8 | {% endblock nav-menu-items %} 9 | 10 | {% block main-content %} 11 |

Update books

12 |

Number of books updated: {{ number_of_books_updated }}

13 | {% endblock %} 14 | {% block sidebar-content %}{% endblock sidebar-content %} 15 | -------------------------------------------------------------------------------- /examples/simple/books/tests/README.rst: -------------------------------------------------------------------------------- 1 | =========== 2 | books.tests 3 | =========== 4 | All tests of the books module. 5 | -------------------------------------------------------------------------------- /examples/simple/books/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/django-elasticsearch-dsl-drf/d83900f2c92b38b00423065795b146434c5a5bf7/examples/simple/books/tests/__init__.py -------------------------------------------------------------------------------- /examples/simple/books/tests/test_browser.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/django-elasticsearch-dsl-drf/d83900f2c92b38b00423065795b146434c5a5bf7/examples/simple/books/tests/test_browser.py -------------------------------------------------------------------------------- /examples/simple/books/tests/test_core.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/django-elasticsearch-dsl-drf/d83900f2c92b38b00423065795b146434c5a5bf7/examples/simple/books/tests/test_core.py -------------------------------------------------------------------------------- /examples/simple/factories/README.rst: -------------------------------------------------------------------------------- 1 | factories 2 | ========= 3 | Project dummy data (dynamic fixtures). Extremely useful if you want to test 4 | your application on a large data set (which you don't have or difficult to 5 | recreate each time for each developer). 6 | 7 | Usage examples 8 | -------------- 9 | **Create a single ``Book`` instance** 10 | 11 | .. code-block:: python 12 | 13 | import factories 14 | 15 | book = factories.BookFactory() 16 | 17 | **Create many (100) ``Book`` instances** 18 | 19 | .. code-block:: python 20 | 21 | import factories 22 | 23 | book = factories.BookFactory.create_batch(100) 24 | 25 | **Create a single ``Book`` instance with pre-defined attributes** 26 | 27 | .. code-block:: python 28 | 29 | book = factories.BookFactory( 30 | title="My book title", 31 | publisher__country="AU", 32 | ) 33 | -------------------------------------------------------------------------------- /examples/simple/factories/__init__.py: -------------------------------------------------------------------------------- 1 | from .auth_user import * 2 | from .books_address import * 3 | from .books_author import * 4 | from .books_book import * 5 | from .books_city import * 6 | from .books_continent import * 7 | from .books_country import * 8 | from .books_galaxy import * 9 | from .books_journal import * 10 | from .books_location import * 11 | from .books_order import * 12 | from .books_orderline import * 13 | from .books_planet import * 14 | from .books_publisher import * 15 | from .books_tag import * 16 | -------------------------------------------------------------------------------- /examples/simple/factories/books_address.py: -------------------------------------------------------------------------------- 1 | from factory import SubFactory 2 | from factory.django import DjangoModelFactory 3 | 4 | from books.models import Address 5 | 6 | from .factory_faker import Faker 7 | 8 | __all__ = ('AddressFactory',) 9 | 10 | 11 | class BaseAddressFactory(DjangoModelFactory): 12 | """Base address factory.""" 13 | 14 | street = Faker('street_name') 15 | house_number = Faker('building_number') 16 | zip_code = Faker('postcode') 17 | city = SubFactory('factories.books_city.CityFactory') 18 | latitude = Faker('latitude') 19 | longitude = Faker('longitude') 20 | planet = SubFactory('factories.books_planet.PlanetFactory') 21 | 22 | class Meta: 23 | """Meta class.""" 24 | 25 | model = Address 26 | abstract = True 27 | 28 | 29 | class AddressFactory(BaseAddressFactory): 30 | """Address factory.""" 31 | -------------------------------------------------------------------------------- /examples/simple/factories/books_author.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | from factory import LazyAttribute 4 | from factory.django import DjangoModelFactory 5 | 6 | from books.models import Author 7 | 8 | from .factory_faker import Faker 9 | 10 | __all__ = ( 11 | 'AuthorFactory', 12 | 'AuthorWithUniqueNameFactory', 13 | 'LimitedAuthorFactory', 14 | 'SingleAuthorFactory', 15 | ) 16 | 17 | 18 | class BaseAuthorFactory(DjangoModelFactory): 19 | """Base author factory.""" 20 | 21 | salutation = Faker('text', max_nb_chars=10) 22 | name = Faker('name') 23 | email = Faker('email') 24 | 25 | class Meta: 26 | """Meta class.""" 27 | 28 | model = Author 29 | abstract = True 30 | 31 | 32 | class AuthorFactory(BaseAuthorFactory): 33 | """Author factory.""" 34 | 35 | 36 | class AuthorWithUniqueNameFactory(BaseAuthorFactory): 37 | """Author factory with unique name attribute.""" 38 | 39 | class Meta: 40 | """Meta class.""" 41 | 42 | django_get_or_create = ('name',) 43 | 44 | 45 | class LimitedAuthorFactory(BaseAuthorFactory): 46 | """Author factory, but limited to 20 authors.""" 47 | 48 | id = LazyAttribute( 49 | lambda __x: random.randint(1, 20) 50 | ) 51 | 52 | class Meta: 53 | """Meta class.""" 54 | 55 | django_get_or_create = ('id',) 56 | 57 | 58 | class SingleAuthorFactory(BaseAuthorFactory): 59 | """Author factory, limited to a single author.""" 60 | 61 | id = 999999 62 | name = "Artur Barseghyan" 63 | email = "barseghyan@gw20e.com" 64 | 65 | class Meta: 66 | """Meta class.""" 67 | 68 | django_get_or_create = ('id',) 69 | -------------------------------------------------------------------------------- /examples/simple/factories/books_continent.py: -------------------------------------------------------------------------------- 1 | from factory.django import DjangoModelFactory 2 | from factory.fuzzy import FuzzyChoice 3 | 4 | from books.models import Continent 5 | 6 | from .factory_faker import Faker 7 | 8 | __all__ = ('ContinentFactory',) 9 | 10 | 11 | class BaseContinentFactory(DjangoModelFactory): 12 | """Base continent factory.""" 13 | 14 | name = FuzzyChoice([ 15 | 'Asia', 16 | 'Africa', 17 | 'North America', 18 | 'South America', 19 | 'Antarctica', 20 | 'Europe', 21 | 'Australia' 22 | ]) 23 | info = Faker('text') 24 | latitude = Faker('latitude') 25 | longitude = Faker('longitude') 26 | 27 | class Meta: 28 | """Meta class.""" 29 | 30 | model = Continent 31 | abstract = True 32 | django_get_or_create = ('name',) 33 | 34 | 35 | class ContinentFactory(BaseContinentFactory): 36 | """Continent factory.""" 37 | -------------------------------------------------------------------------------- /examples/simple/factories/books_country.py: -------------------------------------------------------------------------------- 1 | from factory import SubFactory 2 | from factory.django import DjangoModelFactory 3 | 4 | from books.models import Country 5 | 6 | from .factory_faker import Faker 7 | 8 | __all__ = ('CountryFactory',) 9 | 10 | 11 | class BaseCountryFactory(DjangoModelFactory): 12 | """Base country factory.""" 13 | 14 | name = Faker('country') 15 | info = Faker('text') 16 | continent = SubFactory('factories.books_continent.ContinentFactory') 17 | latitude = Faker('latitude') 18 | longitude = Faker('longitude') 19 | 20 | class Meta: 21 | """Meta class.""" 22 | 23 | model = Country 24 | abstract = True 25 | django_get_or_create = ('name',) 26 | 27 | 28 | class CountryFactory(BaseCountryFactory): 29 | """Country factory.""" 30 | -------------------------------------------------------------------------------- /examples/simple/factories/books_galaxy.py: -------------------------------------------------------------------------------- 1 | from factory import SubFactory 2 | from factory.django import DjangoModelFactory 3 | 4 | from books.models import Galaxy 5 | 6 | from .factory_faker import Faker 7 | 8 | __all__ = ( 9 | 'GalaxyFactory', 10 | ) 11 | 12 | 13 | class BaseGalaxyFactory(DjangoModelFactory): 14 | """Base galaxy factory.""" 15 | 16 | name = Faker('name') 17 | 18 | class Meta: 19 | """Meta class.""" 20 | 21 | model = Galaxy 22 | abstract = True 23 | django_get_or_create = ('name',) 24 | 25 | 26 | class GalaxyFactory(BaseGalaxyFactory): 27 | """Planet factory.""" 28 | -------------------------------------------------------------------------------- /examples/simple/factories/books_location.py: -------------------------------------------------------------------------------- 1 | from factory.django import DjangoModelFactory 2 | from factory.fuzzy import FuzzyChoice 3 | 4 | from books.models import Location 5 | from books.constants import LOCATION_CATEGORY_CHOICES 6 | 7 | from .factory_faker import EnGbFaker as Faker 8 | 9 | __all__ = ('LocationFactory',) 10 | 11 | 12 | class BaseLocationFactory(DjangoModelFactory): 13 | """Base location factory.""" 14 | 15 | group = FuzzyChoice([_choice[0] for _choice in LOCATION_CATEGORY_CHOICES]) 16 | occupation_status = Faker('pybool') 17 | postcode = Faker('postcode') 18 | address_no = Faker('pyint') 19 | address_street = Faker('street_name') 20 | address_town = Faker('city') 21 | authority_name = Faker('company') 22 | # geocode = Faker('postcode') 23 | slug = Faker('uuid4') 24 | floor_area = Faker('pyfloat') 25 | employee_count = Faker('pyfloat') 26 | rental_valuation = Faker('pyfloat') 27 | revenue = Faker('pyfloat') 28 | latitude = Faker('latitude') 29 | longitude = Faker('longitude') 30 | 31 | class Meta: 32 | """Meta class.""" 33 | 34 | model = Location 35 | abstract = True 36 | django_get_or_create = ('slug',) 37 | 38 | 39 | class LocationFactory(BaseLocationFactory): 40 | """Location factory.""" 41 | -------------------------------------------------------------------------------- /examples/simple/factories/books_order.py: -------------------------------------------------------------------------------- 1 | from factory import SubFactory # , post_generation 2 | from factory.django import DjangoModelFactory 3 | 4 | from books.models import Order 5 | 6 | # from .factory_faker import Faker 7 | # from .books_orderline import OrderLineFactory 8 | 9 | __all__ = ('OrderFactory',) 10 | 11 | 12 | class OrderFactory(DjangoModelFactory): 13 | """Order factory.""" 14 | 15 | owner = SubFactory('factories.auth_user.UserFactory') 16 | # created = Faker('date') 17 | # updated = Faker('date') 18 | 19 | class Meta: 20 | """Meta class.""" 21 | 22 | model = Order 23 | 24 | # @post_generation 25 | # def order_lines(obj, created, extracted, **kwargs): 26 | # """Create `OrderLine` objects for the created `Order` instance.""" 27 | # if created: 28 | # # Create 4 `OrderLine` objects. 29 | # order_lines = OrderLineFactory.create_batch(4, **kwargs) 30 | # obj.order_lines.add(*order_lines) 31 | -------------------------------------------------------------------------------- /examples/simple/factories/books_orderline.py: -------------------------------------------------------------------------------- 1 | from factory import SubFactory 2 | from factory.django import DjangoModelFactory 3 | 4 | from books.models import OrderLine 5 | 6 | # from .factory_faker import Faker 7 | 8 | __all__ = ('OrderLineFactory',) 9 | 10 | 11 | class OrderLineFactory(DjangoModelFactory): 12 | """Order line factory.""" 13 | 14 | # owner = SubFactory('factories.books_order.OrderFactory') 15 | book = SubFactory('factories.books_book.BookFactory') 16 | # created = Faker('date') 17 | # updated = Faker('date') 18 | 19 | class Meta: 20 | """Meta class.""" 21 | 22 | model = OrderLine 23 | -------------------------------------------------------------------------------- /examples/simple/factories/books_planet.py: -------------------------------------------------------------------------------- 1 | from factory import SubFactory 2 | from factory.django import DjangoModelFactory 3 | 4 | from books.models import Planet 5 | 6 | from .factory_faker import Faker 7 | 8 | __all__ = ( 9 | 'PlanetFactory', 10 | ) 11 | 12 | 13 | class BasePlanetFactory(DjangoModelFactory): 14 | """Base planet factory.""" 15 | 16 | name = Faker('name') 17 | galaxy = SubFactory('factories.books_galaxy.GalaxyFactory') 18 | 19 | class Meta: 20 | """Meta class.""" 21 | 22 | model = Planet 23 | abstract = True 24 | django_get_or_create = ('name',) 25 | 26 | 27 | class PlanetFactory(BasePlanetFactory): 28 | """Planet factory.""" 29 | -------------------------------------------------------------------------------- /examples/simple/factories/books_tag.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | from factory import LazyAttribute 4 | from factory.django import DjangoModelFactory 5 | from factory.fuzzy import FuzzyChoice 6 | 7 | from books.models import Tag 8 | 9 | from .constants import BOOK_GENRES 10 | from .factory_faker import Faker 11 | 12 | __all__ = ( 13 | 'TagFactory', 14 | 'TagGenreFactory', 15 | 'LimitedTagFactory', 16 | ) 17 | 18 | 19 | class BaseTagFactory(DjangoModelFactory): 20 | """Base tag factory.""" 21 | 22 | # Although the ``max_length`` of the of the ``title`` field of the 23 | # ``Tag`` model is set to 255, for usability we set this one to 20. 24 | title = Faker('catch_phrase') 25 | 26 | class Meta: 27 | """Meta class.""" 28 | 29 | model = Tag 30 | abstract = True 31 | django_get_or_create = ('title',) 32 | 33 | 34 | class TagFactory(BaseTagFactory): 35 | """Tag factory.""" 36 | 37 | 38 | class TagGenreFactory(BaseTagFactory): 39 | """Tag factory consisting of genres.""" 40 | 41 | title = FuzzyChoice(BOOK_GENRES) 42 | 43 | class Meta: 44 | """Meta class.""" 45 | 46 | django_get_or_create = ('title',) 47 | 48 | 49 | class LimitedTagFactory(BaseTagFactory): 50 | """Tag factory, but limited to 20 tags.""" 51 | 52 | id = LazyAttribute( 53 | lambda __x: random.randint(1, 20) 54 | ) 55 | 56 | class Meta: 57 | """Meta class.""" 58 | 59 | django_get_or_create = ('id',) 60 | -------------------------------------------------------------------------------- /examples/simple/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") 7 | 8 | from django.core.management import execute_from_command_line 9 | 10 | execute_from_command_line(sys.argv) 11 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/__init__.py: -------------------------------------------------------------------------------- 1 | from .signals import delete_document, update_document # NOQA 2 | 3 | default_app_config = 'search_indexes.apps.Config' 4 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/apps.py: -------------------------------------------------------------------------------- 1 | try: 2 | from django.apps import AppConfig 3 | 4 | class Config(AppConfig): 5 | """Config.""" 6 | 7 | name = 'search_indexes' 8 | label = 'search_indexes' 9 | 10 | __all__ = ('Config',) 11 | 12 | except ImportError: 13 | pass 14 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/backends/__init__.py: -------------------------------------------------------------------------------- 1 | from .nested_continents import * 2 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/constants.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/django-elasticsearch-dsl-drf/d83900f2c92b38b00423065795b146434c5a5bf7/examples/simple/search_indexes/constants.py -------------------------------------------------------------------------------- /examples/simple/search_indexes/documents/__init__.py: -------------------------------------------------------------------------------- 1 | from .address import AddressDocument 2 | from .author import AuthorDocument 3 | from .book import BookDocument 4 | from .city import CityDocument 5 | from .journal import JournalDocument 6 | from .location import LocationDocument 7 | from .publisher import PublisherDocument 8 | from .tag import TagDocument 9 | 10 | __all___ = ( 11 | 'AddressDocument', 12 | 'AuthorDocument', 13 | 'BookDocument', 14 | 'CityDocument', 15 | 'PublisherDocument', 16 | 'TagDocument', 17 | ) 18 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/documents/analyzers.py: -------------------------------------------------------------------------------- 1 | from elasticsearch_dsl import analyzer 2 | from django_elasticsearch_dsl_drf.versions import ELASTICSEARCH_GTE_7_0 3 | 4 | __all__ = ( 5 | 'html_strip', 6 | ) 7 | 8 | # The ``standard`` filter has been removed in Elasticsearch 7.x. 9 | if ELASTICSEARCH_GTE_7_0: 10 | _filters = ["lowercase", "stop", "snowball"] 11 | else: 12 | _filters = ["standard", "lowercase", "stop", "snowball"] 13 | 14 | html_strip = analyzer( 15 | 'html_strip', 16 | tokenizer="standard", 17 | filter=_filters, 18 | char_filter=["html_strip"] 19 | ) 20 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/documents/tag.py: -------------------------------------------------------------------------------- 1 | from django.conf import settings 2 | from django_elasticsearch_dsl import Document, Index, fields 3 | 4 | from books.models import Tag 5 | from .analyzers import html_strip 6 | 7 | 8 | __all__ = ('TagDocument',) 9 | 10 | INDEX = Index(settings.ELASTICSEARCH_INDEX_NAMES[__name__]) 11 | 12 | INDEX.settings( 13 | number_of_shards=1, 14 | number_of_replicas=1, 15 | blocks={'read_only_allow_delete': None} 16 | ) 17 | 18 | 19 | @INDEX.doc_type 20 | class TagDocument(Document): 21 | """Elasticsearch document for a Tag.""" 22 | 23 | # Set unique title as the document id. 24 | id = fields.KeywordField(attr='title') 25 | title = fields.KeywordField() 26 | 27 | class Django(object): 28 | """Django Elasticsearch DSL ORM Meta.""" 29 | 30 | model = Tag 31 | 32 | class Meta: 33 | """Meta options.""" 34 | 35 | parellel_indexing = True 36 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/serializers/__init__.py: -------------------------------------------------------------------------------- 1 | from .address import ( 2 | AddressDocumentSerializer, 3 | FrontendAddressDocumentSerializer, 4 | ) 5 | from .author import AuthorDocumentSimpleSerializer 6 | from .book import BookDocumentSerializer, BookDocumentSimpleSerializer 7 | from .city import CityDocumentSerializer 8 | from .journal import JournalDocumentSerializer 9 | from .location import LocationDocumentSerializer 10 | from .publisher import ( 11 | PublisherDocumentSerializer, 12 | PublisherDocumentSimpleSerializer, 13 | ) 14 | from .tag import TagDocumentSerializer 15 | 16 | __all__ = ( 17 | 'AddressDocumentSerializer', 18 | 'AuthorDocumentSimpleSerializer', 19 | 'BookDocumentSerializer', 20 | 'BookDocumentSimpleSerializer', 21 | 'CityDocumentSerializer', 22 | 'JournalDocumentSerializer', 23 | 'FrontendAddressDocumentSerializer', 24 | 'LocationDocumentSerializer', 25 | 'PublisherDocumentSerializer', 26 | 'PublisherDocumentSimpleSerializer', 27 | 'TagDocumentSerializer', 28 | ) 29 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/serializers/address.py: -------------------------------------------------------------------------------- 1 | from django_elasticsearch_dsl_drf.serializers import DocumentSerializer 2 | 3 | from ..documents import AddressDocument 4 | 5 | __all__ = ( 6 | 'AddressDocumentSerializer', 7 | 'FrontendAddressDocumentSerializer', 8 | ) 9 | 10 | 11 | class AddressDocumentSerializer(DocumentSerializer): 12 | """Serializer for address document.""" 13 | 14 | class Meta: 15 | """Meta options.""" 16 | 17 | document = AddressDocument 18 | fields = ( 19 | 'id', 20 | 'street', 21 | 'house_number', 22 | 'appendix', 23 | 'zip_code', 24 | 'city', 25 | 'country', 26 | 'continent', 27 | 'location', 28 | ) 29 | 30 | 31 | class FrontendAddressDocumentSerializer(DocumentSerializer): 32 | """Serializer for address document.""" 33 | 34 | class Meta: 35 | """Meta options.""" 36 | 37 | document = AddressDocument 38 | fields = ( 39 | 'id', 40 | 'street', 41 | 'house_number', 42 | 'appendix', 43 | 'zip_code', 44 | 'location', 45 | ) 46 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/serializers/author.py: -------------------------------------------------------------------------------- 1 | from rest_framework import serializers 2 | from django_elasticsearch_dsl_drf.serializers import DocumentSerializer 3 | 4 | from ..documents import AuthorDocument 5 | 6 | __all__ = ('AuthorDocumentSimpleSerializer',) 7 | 8 | 9 | class AuthorDocumentSimpleSerializer(DocumentSerializer): 10 | """Serializer for the Author document.""" 11 | 12 | source = serializers.SerializerMethodField() 13 | 14 | class Meta: 15 | """Meta options.""" 16 | 17 | document = AuthorDocument 18 | # fields = ( 19 | # 'id', 20 | # 'name', 21 | # 'email', 22 | # 'salutation', 23 | # ) 24 | exclude = ( 25 | 'headshot', 26 | ) 27 | ignore_fields = ( 28 | 'biography', 29 | 'phone_number', 30 | 'website', 31 | ) 32 | 33 | def get_source(self, obj): 34 | return obj._d_ 35 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/serializers/city.py: -------------------------------------------------------------------------------- 1 | from rest_framework import serializers 2 | 3 | from django_elasticsearch_dsl_drf.serializers import DocumentSerializer 4 | 5 | from ..documents import CityDocument 6 | 7 | __all__ = ('CityDocumentSerializer',) 8 | 9 | 10 | class CityDocumentSerializer(DocumentSerializer): 11 | """Serializer for city document.""" 12 | 13 | es_id = serializers.SerializerMethodField() 14 | 15 | class Meta: 16 | """Meta options.""" 17 | 18 | document = CityDocument 19 | fields = ( 20 | 'id', 21 | 'name', 22 | 'info', 23 | 'country', 24 | 'location', 25 | 'capital', 26 | 'boolean_list', 27 | 'datetime_list', 28 | 'float_list', 29 | 'integer_list', 30 | 'es_id', 31 | ) 32 | 33 | def get_es_id(self, obj): 34 | if hasattr(obj.meta, 'id'): 35 | return obj.meta.id 36 | return None 37 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/serializers/journal.py: -------------------------------------------------------------------------------- 1 | from rest_framework import serializers 2 | from django_elasticsearch_dsl_drf.serializers import DocumentSerializer 3 | 4 | from ..documents import JournalDocument 5 | 6 | __all__ = ( 7 | 'JournalDocumentSerializer', 8 | ) 9 | 10 | 11 | class JournalDocumentSerializer(DocumentSerializer): 12 | """Serializer for the Book document.""" 13 | 14 | score = serializers.SerializerMethodField() 15 | 16 | class Meta: 17 | """Meta options.""" 18 | 19 | document = JournalDocument 20 | fields = ( 21 | 'title', 22 | 'description', 23 | 'summary', 24 | 'publication_date', 25 | 'isbn', 26 | 'price', 27 | 'pages', 28 | 'stock_count', 29 | 'created', 30 | ) 31 | 32 | def get_score(self, obj): 33 | if hasattr(obj.meta, 'score'): 34 | return obj.meta.score 35 | return None 36 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/serializers/location.py: -------------------------------------------------------------------------------- 1 | from django_elasticsearch_dsl_drf.serializers import DocumentSerializer 2 | 3 | from ..documents import LocationDocument 4 | 5 | 6 | class LocationDocumentSerializer(DocumentSerializer): 7 | """Serializer for Location document.""" 8 | 9 | class Meta: 10 | """Meta options.""" 11 | 12 | # Specify the correspondent document class 13 | document = LocationDocument 14 | 15 | # List the serializer fields. Note, that the order of the fields 16 | # is preserved in the ViewSet. 17 | fields = ( 18 | "full", 19 | "partial", 20 | "geocode", 21 | "slug", 22 | "number", 23 | "address", 24 | "town", 25 | "authority", 26 | "postcode", 27 | "category", 28 | "occupied", 29 | "size", 30 | "staff", 31 | "rent", 32 | "revenue", 33 | "coordinates", 34 | ) 35 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/serializers/tag.py: -------------------------------------------------------------------------------- 1 | from django_elasticsearch_dsl_drf.serializers import DocumentSerializer 2 | 3 | from ..documents import TagDocument 4 | 5 | 6 | __all__ = ('TagDocumentSerializer',) 7 | 8 | 9 | class TagDocumentSerializer(DocumentSerializer): 10 | """Serializer for a Tag document.""" 11 | 12 | class Meta: 13 | """Meta options.""" 14 | 15 | document = TagDocument 16 | fields = ( 17 | 'id', 18 | 'title', 19 | ) 20 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/viewsets/__init__.py: -------------------------------------------------------------------------------- 1 | from .address import * 2 | from .author import * 3 | from .book import * 4 | from .city import * 5 | from .journal import * 6 | from .location import * 7 | from .publisher import * 8 | from .tag import * 9 | 10 | __all__ = ( 11 | 'AddressDocumentViewSet', 12 | 'AuthorDocumentViewSet', 13 | 'BookCompoundFuzzySearchBackendDocumentViewSet', 14 | 'BookCompoundSearchBackendDocumentViewSet', 15 | 'BookCompoundSearchBoostSearchBackendDocumentViewSet', 16 | 'BookCustomDocumentViewSet', 17 | 'BookDefaultFilterLookupDocumentViewSet', 18 | 'BookDocumentViewSet', 19 | 'BookFrontendDocumentViewSet', 20 | 'BookFunctionalSuggesterDocumentViewSet', 21 | 'BookIgnoreIndexErrorsDocumentViewSet', 22 | 'BookMoreLikeThisDocumentViewSet', 23 | 'BookMoreLikeThisNoOptionsDocumentViewSet', 24 | 'BookMultiMatchOptionsPhasePrefixSearchFilterBackendDocumentViewSet', 25 | 'BookMultiMatchSearchFilterBackendDocumentViewSet', 26 | 'BookOrderingByScoreCompoundSearchBackendDocumentViewSet', 27 | 'BookOrderingByScoreDocumentViewSet', 28 | 'BookPermissionsDocumentViewSet', 29 | 'BookNoPermissionsDocumentViewSet', 30 | 'BookNoRecordsDocumentViewSet', 31 | 'BookSimpleQueryStringBoostSearchFilterBackendDocumentViewSet', 32 | 'BookSimpleQueryStringSearchFilterBackendDocumentViewSet', 33 | 'BookSourceSearchBackendDocumentViewSet', 34 | 'CityCompoundSearchBackendDocumentViewSet', 35 | 'CityDocumentViewSet', 36 | 'JournalDocumentViewSet', 37 | 'FrontAddressDocumentViewSet', 38 | 'FacetedFilteredBookDocumentViewSet', 39 | 'LocationDocumentViewSet', 40 | 'PublisherDocumentViewSet', 41 | 'QueryFriendlyPaginationBookDocumentViewSet', 42 | 'TagDocumentViewSet', 43 | ) 44 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/viewsets/address/__init__.py: -------------------------------------------------------------------------------- 1 | from .default import AddressDocumentViewSet 2 | from .frontend import FrontAddressDocumentViewSet 3 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/viewsets/book/__init__.py: -------------------------------------------------------------------------------- 1 | from .base import * 2 | from .compound_search import * 3 | from .compound_search_boost import * 4 | from .default import * 5 | from .default_filter_lookup import * 6 | from .faceted_filtered import * 7 | from .functional_suggester import * 8 | from .ignore_index_errors import * 9 | from .frontend import * 10 | from .more_like_this import * 11 | from .multi_match import * 12 | from .multi_match_options_phrase_prefix import * 13 | from .no_records import * 14 | from .ordering_by_score import * 15 | from .ordering_by_score_compound_search import * 16 | from .permissions import * 17 | from .query_friendly_pagination import * 18 | from .simple_query_string import * 19 | from .simple_query_string_boost import * 20 | from .source import * 21 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/viewsets/book/compound_search.py: -------------------------------------------------------------------------------- 1 | from django_elasticsearch_dsl_drf.filter_backends import ( 2 | CompoundSearchFilterBackend, 3 | DefaultOrderingFilterBackend, 4 | FacetedSearchFilterBackend, 5 | FilteringFilterBackend, 6 | HighlightBackend, 7 | IdsFilterBackend, 8 | OrderingFilterBackend, 9 | PostFilterFilteringFilterBackend, 10 | SuggesterFilterBackend, 11 | ) 12 | 13 | from .default import BookDocumentViewSet 14 | 15 | __all__ = ( 16 | 'BookCompoundSearchBackendDocumentViewSet', 17 | 'BookCompoundFuzzySearchBackendDocumentViewSet', 18 | ) 19 | 20 | 21 | class BookCompoundSearchBackendDocumentViewSet(BookDocumentViewSet): 22 | """Book document view set based on compound search backend.""" 23 | 24 | filter_backends = [ 25 | FilteringFilterBackend, 26 | PostFilterFilteringFilterBackend, 27 | IdsFilterBackend, 28 | OrderingFilterBackend, 29 | DefaultOrderingFilterBackend, 30 | CompoundSearchFilterBackend, 31 | FacetedSearchFilterBackend, 32 | HighlightBackend, 33 | SuggesterFilterBackend, 34 | ] 35 | 36 | 37 | class BookCompoundFuzzySearchBackendDocumentViewSet(BookDocumentViewSet): 38 | """Book document view set based on compound search backend.""" 39 | 40 | filter_backends = [ 41 | FilteringFilterBackend, 42 | PostFilterFilteringFilterBackend, 43 | IdsFilterBackend, 44 | OrderingFilterBackend, 45 | DefaultOrderingFilterBackend, 46 | CompoundSearchFilterBackend, 47 | FacetedSearchFilterBackend, 48 | HighlightBackend, 49 | SuggesterFilterBackend, 50 | ] 51 | 52 | search_fields = { 53 | 'title': {'fuzziness': 'AUTO'}, 54 | 'description': None, 55 | 'summary': None, 56 | } 57 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/viewsets/book/compound_search_boost.py: -------------------------------------------------------------------------------- 1 | from django_elasticsearch_dsl_drf.filter_backends import ( 2 | CompoundSearchFilterBackend, 3 | DefaultOrderingFilterBackend, 4 | FacetedSearchFilterBackend, 5 | FilteringFilterBackend, 6 | HighlightBackend, 7 | IdsFilterBackend, 8 | OrderingFilterBackend, 9 | PostFilterFilteringFilterBackend, 10 | SuggesterFilterBackend, 11 | ) 12 | 13 | from .default import BookDocumentViewSet 14 | 15 | __all__ = ( 16 | 'BookCompoundSearchBoostSearchBackendDocumentViewSet', 17 | ) 18 | 19 | 20 | class BookCompoundSearchBoostSearchBackendDocumentViewSet(BookDocumentViewSet): 21 | """Book document view set based on compound search backend.""" 22 | 23 | filter_backends = [ 24 | FilteringFilterBackend, 25 | PostFilterFilteringFilterBackend, 26 | IdsFilterBackend, 27 | OrderingFilterBackend, 28 | DefaultOrderingFilterBackend, 29 | CompoundSearchFilterBackend, 30 | FacetedSearchFilterBackend, 31 | HighlightBackend, 32 | SuggesterFilterBackend, 33 | ] 34 | 35 | # Define search fields 36 | search_fields = { 37 | 'title': {'boost': 2}, 38 | 'description': None, 39 | 'summary': None, 40 | } 41 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/viewsets/book/default_filter_lookup.py: -------------------------------------------------------------------------------- 1 | from django_elasticsearch_dsl_drf.constants import ( 2 | LOOKUP_FILTER_PREFIX, 3 | LOOKUP_FILTER_TERM, 4 | LOOKUP_FILTER_TERMS, 5 | LOOKUP_FILTER_WILDCARD, 6 | LOOKUP_QUERY_EXCLUDE, 7 | LOOKUP_QUERY_IN, 8 | ) 9 | 10 | from .default import BookDocumentViewSet 11 | 12 | __all__ = ( 13 | 'BookDefaultFilterLookupDocumentViewSet', 14 | ) 15 | 16 | 17 | class BookDefaultFilterLookupDocumentViewSet(BookDocumentViewSet): 18 | """Same as parent, but with default filter lookups & no default facets.""" 19 | 20 | filter_fields = { 21 | 'authors': { 22 | 'field': 'authors.raw', 23 | 'lookups': [ 24 | LOOKUP_FILTER_TERM, 25 | LOOKUP_FILTER_TERMS, 26 | LOOKUP_FILTER_PREFIX, 27 | LOOKUP_FILTER_WILDCARD, 28 | LOOKUP_QUERY_IN, 29 | LOOKUP_QUERY_EXCLUDE, 30 | ], 31 | 'default_lookup': LOOKUP_FILTER_TERM, 32 | }, 33 | 'publisher': 'publisher.raw', 34 | } 35 | 36 | faceted_search_fields = { 37 | 'state': 'state.raw', 38 | 'publisher': { 39 | 'field': 'publisher.raw', 40 | 'enabled': False, 41 | }, 42 | } 43 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/viewsets/book/faceted_filtered.py: -------------------------------------------------------------------------------- 1 | from django_elasticsearch_dsl_drf.filter_backends import ( 2 | DefaultOrderingFilterBackend, 3 | FacetedFilterSearchFilterBackend, 4 | ) 5 | 6 | from .base import BaseBookDocumentViewSet 7 | 8 | 9 | __all__ = ( 10 | 'FacetedFilteredBookDocumentViewSet', 11 | ) 12 | 13 | 14 | class FacetedFilteredBookDocumentViewSet(BaseBookDocumentViewSet): 15 | """The BookDocument view with faceted filtering.""" 16 | 17 | filter_backends = [ 18 | FacetedFilterSearchFilterBackend, 19 | DefaultOrderingFilterBackend, 20 | ] 21 | 22 | filter_fields = { 23 | 'title': 'title.raw', 24 | 'state': 'state.raw', 25 | } 26 | 27 | faceted_search_fields = { 28 | 'state': 'state.raw', 29 | } 30 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/viewsets/book/ignore_index_errors.py: -------------------------------------------------------------------------------- 1 | from .default import BookDocumentViewSet 2 | 3 | __all__ = ( 4 | 'BookIgnoreIndexErrorsDocumentViewSet', 5 | ) 6 | 7 | 8 | class BookIgnoreIndexErrorsDocumentViewSet(BookDocumentViewSet): 9 | """Book document view set based on compound search backend.""" 10 | 11 | ignore = [404] 12 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/viewsets/book/multi_match.py: -------------------------------------------------------------------------------- 1 | from django_elasticsearch_dsl_drf.filter_backends import ( 2 | DefaultOrderingFilterBackend, 3 | FacetedSearchFilterBackend, 4 | FilteringFilterBackend, 5 | HighlightBackend, 6 | IdsFilterBackend, 7 | MultiMatchSearchFilterBackend, 8 | OrderingFilterBackend, 9 | PostFilterFilteringFilterBackend, 10 | SuggesterFilterBackend, 11 | ) 12 | 13 | from .default import BookDocumentViewSet 14 | 15 | __all__ = ( 16 | 'BookMultiMatchSearchFilterBackendDocumentViewSet', 17 | ) 18 | 19 | 20 | class BookMultiMatchSearchFilterBackendDocumentViewSet( 21 | BookDocumentViewSet 22 | ): 23 | """Same as BookDocumentViewSet, but multi match.""" 24 | 25 | filter_backends = [ 26 | FilteringFilterBackend, 27 | PostFilterFilteringFilterBackend, 28 | IdsFilterBackend, 29 | OrderingFilterBackend, 30 | DefaultOrderingFilterBackend, 31 | MultiMatchSearchFilterBackend, 32 | FacetedSearchFilterBackend, 33 | HighlightBackend, 34 | SuggesterFilterBackend, 35 | ] 36 | 37 | search_fields = ( 38 | 'title', 39 | 'summary', 40 | 'description', 41 | ) 42 | ordering = ('_score', 'id', 'title', 'price',) 43 | 44 | multi_match_options = { 45 | 'type': 'phrase', 46 | } 47 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/viewsets/book/multi_match_options_phrase_prefix.py: -------------------------------------------------------------------------------- 1 | from django_elasticsearch_dsl_drf.filter_backends import ( 2 | DefaultOrderingFilterBackend, 3 | FacetedSearchFilterBackend, 4 | FilteringFilterBackend, 5 | HighlightBackend, 6 | IdsFilterBackend, 7 | MultiMatchSearchFilterBackend, 8 | OrderingFilterBackend, 9 | PostFilterFilteringFilterBackend, 10 | SuggesterFilterBackend, 11 | ) 12 | 13 | from .multi_match import BookMultiMatchSearchFilterBackendDocumentViewSet 14 | 15 | __all__ = ( 16 | 'BookMultiMatchOptionsPhasePrefixSearchFilterBackendDocumentViewSet', 17 | ) 18 | 19 | 20 | class BookMultiMatchOptionsPhasePrefixSearchFilterBackendDocumentViewSet( 21 | BookMultiMatchSearchFilterBackendDocumentViewSet 22 | ): 23 | """Same as parent, but uses `multi_match_search_fields` declarations. 24 | 25 | Additionally, uses `phase_prefix`. 26 | """ 27 | 28 | filter_backends = [ 29 | FilteringFilterBackend, 30 | PostFilterFilteringFilterBackend, 31 | IdsFilterBackend, 32 | OrderingFilterBackend, 33 | DefaultOrderingFilterBackend, 34 | MultiMatchSearchFilterBackend, 35 | FacetedSearchFilterBackend, 36 | HighlightBackend, 37 | SuggesterFilterBackend, 38 | ] 39 | 40 | multi_match_search_fields = { 41 | 'title': {'boost': 4}, 42 | 'summary': {'boost': 2}, 43 | 'description': None, 44 | } 45 | ordering = ('_score', 'id', 'title', 'price',) 46 | 47 | multi_match_options = { 48 | 'type': 'phrase_prefix', 49 | } 50 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/viewsets/book/no_records.py: -------------------------------------------------------------------------------- 1 | from django_elasticsearch_dsl_drf.utils import EmptySearch 2 | 3 | from .default import BookDocumentViewSet 4 | 5 | __all__ = ( 6 | 'BookNoRecordsDocumentViewSet', 7 | ) 8 | 9 | 10 | class BookNoRecordsDocumentViewSet(BookDocumentViewSet): 11 | """Book document view set based on compound search backend.""" 12 | 13 | def get_queryset(self): 14 | queryset = EmptySearch() 15 | queryset.model = self.document.Django.model 16 | return queryset 17 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/viewsets/book/ordering_by_score.py: -------------------------------------------------------------------------------- 1 | from .default import BookDocumentViewSet 2 | 3 | __all__ = ( 4 | 'BookOrderingByScoreDocumentViewSet', 5 | ) 6 | 7 | 8 | class BookOrderingByScoreDocumentViewSet(BookDocumentViewSet): 9 | """Same as BookDocumentViewSet, but sorted by _score.""" 10 | 11 | search_fields = { 12 | 'title': {'boost': 4}, 13 | 'summary': {'boost': 2}, 14 | 'description': None, 15 | } 16 | ordering = ('_score', 'id', 'title', 'price',) 17 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/viewsets/book/ordering_by_score_compound_search.py: -------------------------------------------------------------------------------- 1 | from django_elasticsearch_dsl_drf.filter_backends import ( 2 | CompoundSearchFilterBackend, 3 | DefaultOrderingFilterBackend, 4 | FacetedSearchFilterBackend, 5 | FilteringFilterBackend, 6 | HighlightBackend, 7 | IdsFilterBackend, 8 | OrderingFilterBackend, 9 | PostFilterFilteringFilterBackend, 10 | SuggesterFilterBackend, 11 | ) 12 | 13 | from .default import BookDocumentViewSet 14 | 15 | __all__ = ( 16 | 'BookOrderingByScoreCompoundSearchBackendDocumentViewSet', 17 | ) 18 | 19 | 20 | class BookOrderingByScoreCompoundSearchBackendDocumentViewSet( 21 | BookDocumentViewSet 22 | ): 23 | """Same as BookDocumentViewSet, but sorted by _score.""" 24 | 25 | filter_backends = [ 26 | FilteringFilterBackend, 27 | PostFilterFilteringFilterBackend, 28 | IdsFilterBackend, 29 | OrderingFilterBackend, 30 | DefaultOrderingFilterBackend, 31 | CompoundSearchFilterBackend, 32 | FacetedSearchFilterBackend, 33 | HighlightBackend, 34 | SuggesterFilterBackend, 35 | ] 36 | 37 | search_fields = { 38 | 'title': {'boost': 4}, 39 | 'summary': {'boost': 2}, 40 | 'description': None, 41 | } 42 | ordering = ('_score', 'id', 'title', 'price',) 43 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/viewsets/book/query_friendly_pagination.py: -------------------------------------------------------------------------------- 1 | from django_elasticsearch_dsl_drf.pagination import ( 2 | QueryFriendlyPageNumberPagination 3 | ) 4 | from .default import BookDocumentViewSet 5 | 6 | __all__ = ( 7 | 'QueryFriendlyPaginationBookDocumentViewSet', 8 | ) 9 | 10 | 11 | class QueryFriendlyPaginationBookDocumentViewSet(BookDocumentViewSet): 12 | 13 | pagination_class = QueryFriendlyPageNumberPagination 14 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/viewsets/book/simple_query_string.py: -------------------------------------------------------------------------------- 1 | from django_elasticsearch_dsl_drf.filter_backends import ( 2 | DefaultOrderingFilterBackend, 3 | FacetedSearchFilterBackend, 4 | FilteringFilterBackend, 5 | HighlightBackend, 6 | IdsFilterBackend, 7 | SimpleQueryStringSearchFilterBackend, 8 | OrderingFilterBackend, 9 | PostFilterFilteringFilterBackend, 10 | SuggesterFilterBackend, 11 | ) 12 | 13 | from .default import BookDocumentViewSet 14 | 15 | __all__ = ( 16 | 'BookSimpleQueryStringSearchFilterBackendDocumentViewSet', 17 | ) 18 | 19 | 20 | class BookSimpleQueryStringSearchFilterBackendDocumentViewSet( 21 | BookDocumentViewSet 22 | ): 23 | """Same as BookDocumentViewSet, but simple query string.""" 24 | 25 | filter_backends = [ 26 | FilteringFilterBackend, 27 | PostFilterFilteringFilterBackend, 28 | IdsFilterBackend, 29 | OrderingFilterBackend, 30 | DefaultOrderingFilterBackend, 31 | SimpleQueryStringSearchFilterBackend, 32 | FacetedSearchFilterBackend, 33 | HighlightBackend, 34 | SuggesterFilterBackend, 35 | ] 36 | 37 | # Using traditional search_fields here. 38 | search_fields = { 39 | 'title': None, 40 | 'summary': None, 41 | 'description': None, 42 | } 43 | ordering = ('_score', 'id', 'title', 'price',) 44 | 45 | simple_query_string_options = { 46 | "default_operator": "and", 47 | } 48 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/viewsets/book/simple_query_string_boost.py: -------------------------------------------------------------------------------- 1 | from django_elasticsearch_dsl_drf.filter_backends import ( 2 | DefaultOrderingFilterBackend, 3 | FacetedSearchFilterBackend, 4 | FilteringFilterBackend, 5 | HighlightBackend, 6 | IdsFilterBackend, 7 | SimpleQueryStringSearchFilterBackend, 8 | OrderingFilterBackend, 9 | PostFilterFilteringFilterBackend, 10 | SuggesterFilterBackend, 11 | ) 12 | 13 | from .default import BookDocumentViewSet 14 | 15 | __all__ = ( 16 | 'BookSimpleQueryStringBoostSearchFilterBackendDocumentViewSet', 17 | ) 18 | 19 | 20 | class BookSimpleQueryStringBoostSearchFilterBackendDocumentViewSet( 21 | BookDocumentViewSet 22 | ): 23 | """Same as BookDocumentViewSet, but simple query string and boost.""" 24 | 25 | filter_backends = [ 26 | FilteringFilterBackend, 27 | PostFilterFilteringFilterBackend, 28 | IdsFilterBackend, 29 | OrderingFilterBackend, 30 | DefaultOrderingFilterBackend, 31 | SimpleQueryStringSearchFilterBackend, 32 | FacetedSearchFilterBackend, 33 | HighlightBackend, 34 | SuggesterFilterBackend, 35 | ] 36 | 37 | # Using dedicated search fields here 38 | simple_query_string_search_fields = { 39 | 'title': None, 40 | 'summary': None, 41 | 'description': None, 42 | } 43 | ordering = ('_score', 'id', 'title', 'price',) 44 | 45 | simple_query_string_options = { 46 | "default_operator": "and", 47 | } 48 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/viewsets/book/source.py: -------------------------------------------------------------------------------- 1 | from django_elasticsearch_dsl_drf.filter_backends import ( 2 | CompoundSearchFilterBackend, 3 | DefaultOrderingFilterBackend, 4 | FacetedSearchFilterBackend, 5 | FilteringFilterBackend, 6 | HighlightBackend, 7 | IdsFilterBackend, 8 | OrderingFilterBackend, 9 | PostFilterFilteringFilterBackend, 10 | SourceBackend, 11 | SuggesterFilterBackend, 12 | ) 13 | 14 | from .default import BookDocumentViewSet 15 | from ...serializers.book import BookDocumentSourceSerializer 16 | 17 | __all__ = ( 18 | 'BookSourceSearchBackendDocumentViewSet', 19 | ) 20 | 21 | 22 | class BookSourceSearchBackendDocumentViewSet(BookDocumentViewSet): 23 | """Book document view set based on compound search backend using source.""" 24 | 25 | filter_backends = [ 26 | SourceBackend, 27 | FilteringFilterBackend, 28 | PostFilterFilteringFilterBackend, 29 | IdsFilterBackend, 30 | OrderingFilterBackend, 31 | DefaultOrderingFilterBackend, 32 | CompoundSearchFilterBackend, 33 | FacetedSearchFilterBackend, 34 | HighlightBackend, 35 | SuggesterFilterBackend, 36 | ] 37 | 38 | serializer_class = BookDocumentSourceSerializer 39 | 40 | source = [ 41 | "id", 42 | "title", 43 | ] 44 | -------------------------------------------------------------------------------- /examples/simple/search_indexes/viewsets/tag.py: -------------------------------------------------------------------------------- 1 | from django_elasticsearch_dsl_drf.pagination import LimitOffsetPagination 2 | from django_elasticsearch_dsl_drf.viewsets import DocumentViewSet 3 | 4 | from ..documents import TagDocument 5 | from ..serializers import TagDocumentSerializer 6 | 7 | __all__ = ( 8 | 'TagDocumentViewSet', 9 | ) 10 | 11 | 12 | class TagDocumentViewSet(DocumentViewSet): 13 | """Document viewset for tags.""" 14 | 15 | document = TagDocument 16 | serializer_class = TagDocumentSerializer 17 | lookup_field = 'title' 18 | filter_backends = [] 19 | pagination_class = LimitOffsetPagination 20 | -------------------------------------------------------------------------------- /examples/simple/settings/README.rst: -------------------------------------------------------------------------------- 1 | settings 2 | ======== 3 | Setting modules. 4 | -------------------------------------------------------------------------------- /examples/simple/settings/__init__.example: -------------------------------------------------------------------------------- 1 | from .dev import * 2 | -------------------------------------------------------------------------------- /examples/simple/settings/__init__.py: -------------------------------------------------------------------------------- 1 | from .dev import * 2 | -------------------------------------------------------------------------------- /examples/simple/settings/core.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | __all__ = ( 4 | 'gettext', 5 | 'project_dir', 6 | 'PROJECT_DIR', 7 | ) 8 | 9 | 10 | def project_dir(base): 11 | """Absolute path to a file from current directory.""" 12 | return os.path.abspath( 13 | os.path.join(os.path.dirname(__file__), base).replace('\\', '/') 14 | ) 15 | 16 | 17 | def gettext(val): 18 | """Dummy gettext.""" 19 | return val 20 | 21 | 22 | PROJECT_DIR = project_dir 23 | -------------------------------------------------------------------------------- /examples/simple/settings/dev.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | from .base import * 4 | 5 | # if LOGGING: 6 | # LOGGING['loggers'].update( 7 | # { 8 | # 'django.db': { 9 | # 'handlers': ['console'], 10 | # 'level': 'DEBUG', 11 | # 'propagate': False, 12 | # } 13 | # } 14 | # ) 15 | 16 | # es_logger = logging.getLogger('elasticsearch') 17 | # es_logger.propagate = False 18 | # es_logger.setLevel(logging.DEBUG) 19 | # console_handler = logging.StreamHandler() 20 | # # formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') 21 | # # console_handler.setFormatter(formatter) 22 | # es_logger.addHandler(console_handler) 23 | -------------------------------------------------------------------------------- /examples/simple/settings/dev_elastic_6.py: -------------------------------------------------------------------------------- 1 | from .base import * 2 | 3 | if LOGGING: 4 | LOGGING['loggers'].update( 5 | { 6 | 'django.db': { 7 | 'handlers': ['console'], 8 | 'level': 'DEBUG', 9 | 'propagate': False, 10 | } 11 | } 12 | ) 13 | 14 | 15 | # Elasticsearch configuration 16 | ELASTICSEARCH_DSL = { 17 | 'default': { 18 | 'hosts': 'localhost:9201', 19 | 'timeout': 30, 20 | }, 21 | } 22 | -------------------------------------------------------------------------------- /examples/simple/settings/docker.py: -------------------------------------------------------------------------------- 1 | import os 2 | from .base import * 3 | 4 | DEBUG = True 5 | DEBUG_TOOLBAR = True 6 | DEBUG_TEMPLATE = True 7 | DEV = True 8 | 9 | DATABASES = { 10 | 'default': { 11 | 'ENGINE': 'django.db.backends.sqlite3', 12 | 'NAME': '/backend/examples/db/docker.db', 13 | 'USER': 'postgres', 14 | 'PASSWORD': 'test', 15 | 'HOST': '', 16 | 'PORT': '', 17 | } 18 | } 19 | 20 | INTERNAL_IPS = ('127.0.0.1',) 21 | 22 | EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend' 23 | EMAIL_FILE_PATH = '/backend/var/' 24 | 25 | DEFAULT_FROM_EMAIL = '' 26 | 27 | os.environ.setdefault( 28 | 'DJANGO_ELASTICSEARCH_DSL_DRF_SOURCE_PATH', 29 | '/backend/src' 30 | ) 31 | 32 | # Elasticsearch configuration 33 | ELASTICSEARCH_DSL = { 34 | 'default': { 35 | 'hosts': 'elasticsearch:9200', 36 | 'timeout': 30, 37 | }, 38 | } 39 | -------------------------------------------------------------------------------- /examples/simple/settings/docs.py: -------------------------------------------------------------------------------- 1 | from .base import * 2 | 3 | LOGGING = {} 4 | -------------------------------------------------------------------------------- /examples/simple/settings/local_settings.example: -------------------------------------------------------------------------------- 1 | import os 2 | from .core import PROJECT_DIR 3 | 4 | 5 | DEBUG = True 6 | DEBUG_TOOLBAR = True 7 | DEBUG_TEMPLATE = True 8 | DEV = True 9 | 10 | DATABASES = { 11 | 'default': { 12 | # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3'. 13 | 'ENGINE': 'django.db.backends.sqlite3', 14 | # 'ENGINE': 'django.db.backends.postgresql', 15 | # Or path to database file if using sqlite3. 16 | 'NAME': PROJECT_DIR('../../db/example.db'), 17 | # 'NAME': 'django_elasticsearch_dsl_drf', 18 | # The following settings are not used with sqlite3: 19 | 'USER': 'postgres', 20 | 'PASSWORD': 'test', 21 | # Empty for localhost through domain sockets or '127.0.0.1' for 22 | # localhost through TCP. 23 | 'HOST': '', 24 | # Set to empty string for default. 25 | 'PORT': '', 26 | } 27 | } 28 | 29 | DATA_UPLOAD_MAX_NUMBER_FIELDS = 10000000 30 | INTERNAL_IPS = ('127.0.0.1',) 31 | 32 | EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend' 33 | EMAIL_FILE_PATH = PROJECT_DIR('../../tmp') 34 | 35 | DEFAULT_FROM_EMAIL = '' 36 | 37 | os.environ.setdefault( 38 | 'DJANGO_ELASTICSEARCH_DSL_DRF_SOURCE_PATH', 39 | '/home/user/repositories/django-elasticsearch-dsl-drf/src' 40 | ) 41 | 42 | # LOGGING = {} # Disable logging 43 | 44 | # LOGGING = {} # Disable logging 45 | 46 | # ELASTICSEARCH_DSL_SIGNAL_PROCESSOR = \ 47 | # 'django_elasticsearch_dsl.signals.BaseSignalProcessor' 48 | -------------------------------------------------------------------------------- /examples/simple/templates/README.rst: -------------------------------------------------------------------------------- 1 | templates 2 | ========= 3 | Base templates and snippets. 4 | -------------------------------------------------------------------------------- /examples/simple/templates/home.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | 3 | {% block meta-title %}Home{% endblock %} 4 | {% block main-content %} 5 |
6 | {#

Home

#} 7 | {#

Landing page content.

#} 8 |
9 | {% endblock main-content %} 10 | 11 | {% block sidebar-content %}{% endblock sidebar-content %} 12 | -------------------------------------------------------------------------------- /examples/simple/templates/snippets/article.html: -------------------------------------------------------------------------------- 1 |
2 |

Blog Post Title

3 |
Written by John Smith on August 12, 2012.
4 |
5 |
6 |

Bacon ipsum dolor sit amet nulla ham qui sint exercitation eiusmod commodo, chuck duis velit. Aute in reprehenderit, dolore aliqua non est magna in labore pig pork biltong. Eiusmod swine spare ribs reprehenderit culpa.

7 |

Boudin aliqua adipisicing rump corned beef. Nulla corned beef sunt ball tip, qui bresaola enim jowl. Capicola short ribs minim salami nulla nostrud pastrami.

8 |
9 |
10 | 11 |
12 |
13 |

Pork drumstick turkey fugiat. Tri-tip elit turducken pork chop in. Swine short ribs meatball irure bacon nulla pork belly cupidatat meatloaf cow. Nulla corned beef sunt ball tip, qui bresaola enim jowl. Capicola short ribs minim salami nulla nostrud pastrami. Nulla corned beef sunt ball tip, qui bresaola enim jowl. Capicola short ribs minim salami nulla nostrud pastrami.

14 |

Pork drumstick turkey fugiat. Tri-tip elit turducken pork chop in. Swine short ribs meatball irure bacon nulla pork belly cupidatat meatloaf cow. Nulla corned beef sunt ball tip, qui bresaola enim jowl. Capicola short ribs minim salami nulla nostrud pastrami.

15 |
-------------------------------------------------------------------------------- /examples/simple/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf.urls import include, url 2 | from django.conf import settings 3 | from django.contrib import admin 4 | from django.contrib.staticfiles.urls import staticfiles_urlpatterns 5 | from django.conf.urls.static import static 6 | from django.views.generic import TemplateView 7 | 8 | from nine import versions 9 | 10 | from books import urls as books_urls 11 | from search_indexes import urls as search_index_urls 12 | 13 | __all__ = ('urlpatterns',) 14 | 15 | admin.autodiscover() 16 | 17 | urlpatterns = [] 18 | urlpatterns_args = [] 19 | 20 | if versions.DJANGO_GTE_2_0: 21 | urlpatterns_args += [ 22 | url(r'^admin/', admin.site.urls), 23 | ] 24 | else: 25 | urlpatterns_args += [ 26 | url(r'^admin/', include(admin.site.urls)), 27 | ] 28 | 29 | urlpatterns_args += [ 30 | # Books URLs 31 | url(r'^books/', include(books_urls)), 32 | 33 | # Search URLs 34 | url(r'^search/', include(search_index_urls)), 35 | 36 | # Home page 37 | url(r'^$', TemplateView.as_view(template_name='home.html')), 38 | ] 39 | 40 | urlpatterns += urlpatterns_args[:] 41 | 42 | # Serving media and static in debug/developer mode. 43 | if settings.DEBUG: 44 | urlpatterns += staticfiles_urlpatterns() 45 | urlpatterns += static( 46 | settings.MEDIA_URL, 47 | document_root=settings.MEDIA_ROOT 48 | ) 49 | 50 | if settings.DEBUG_TOOLBAR is True: 51 | import debug_toolbar 52 | 53 | urlpatterns = [ 54 | url(r'^__debug__/', include(debug_toolbar.urls)), 55 | ] + urlpatterns 56 | -------------------------------------------------------------------------------- /examples/simple/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for example project. 3 | 4 | This module contains the WSGI application used by Django's development server 5 | and any production WSGI deployments. It should expose a module-level variable 6 | named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover 7 | this application via the ``WSGI_APPLICATION`` setting. 8 | 9 | Usually you will have the standard Django WSGI application here, but it also 10 | might make sense to replace the whole Django WSGI application with a custom one 11 | that later delegates to the Django one. For example, you could introduce WSGI 12 | middleware here, or combine a Django application with an application of another 13 | framework. 14 | 15 | """ 16 | import os 17 | 18 | from django.core.wsgi import get_wsgi_application 19 | 20 | # We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks 21 | # if running multiple sites in the same mod_wsgi process. To fix this, use 22 | # mod_wsgi daemon mode with each site in its own daemon process, or use 23 | # os.environ["DJANGO_SETTINGS_MODULE"] = "example.settings" 24 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings") 25 | 26 | # This application object is used by any WSGI server configured to use this 27 | # file. This includes Django's development server, if the WSGI_APPLICATION 28 | # setting points here. 29 | application = get_wsgi_application() 30 | 31 | # Apply WSGI middleware here. 32 | # from helloworld.wsgi import HelloWorldApplication 33 | # application = HelloWorldApplication(application) 34 | -------------------------------------------------------------------------------- /pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | norecursedirs= 3 | *.egg 4 | .hg 5 | .git 6 | .tox 7 | .env 8 | _sass 9 | build 10 | dist 11 | migrations 12 | releases 13 | forks 14 | demos 15 | python_files = 16 | test_*.py 17 | tests.py 18 | python_paths = 19 | src 20 | examples/simple 21 | DJANGO_SETTINGS_MODULE=settings.testing 22 | addopts= 23 | --cov=django_elasticsearch_dsl_drf 24 | --ignore=.tox 25 | --ignore=requirements 26 | --ignore=var 27 | --ignore=releases 28 | --cov-report=html 29 | --cov-report=term 30 | --cov-report=annotate 31 | --cov-append 32 | --capture=no 33 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | -r examples/requirements/base.txt 2 | -------------------------------------------------------------------------------- /runtests.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | import pytest 6 | 7 | 8 | def main(): 9 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.testing") 10 | sys.path.insert(0, "src") 11 | sys.path.insert(0, "examples/simple") 12 | return pytest.main() 13 | 14 | 15 | if __name__ == '__main__': 16 | sys.exit(main()) 17 | -------------------------------------------------------------------------------- /scripts/build_docs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ./scripts/prepare_docs.sh 3 | 4 | sphinx-build -n -a -b html docs builddocs 5 | sphinx-build -n -a -b rinoh docs builddocs 6 | cd builddocs && zip -r ../builddocs.zip . -x ".*" && cd .. 7 | -------------------------------------------------------------------------------- /scripts/clean_up.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | find . -name "*.pyc" -exec rm -rf {} \; 3 | find . -name "__pycache__" -exec rm -rf {} \; 4 | find . -name "*.orig" -exec rm -rf {} \; 5 | find . -name "*.py,cover" -exec rm -rf {} \; 6 | find . -name "*.log" -exec rm -rf {} \; 7 | find . -name "*.log.*" -exec rm -rf {} \; 8 | rm -rf build/ 9 | rm -rf dist/ 10 | rm -rf .cache/ 11 | rm -rf htmlcov/ 12 | -------------------------------------------------------------------------------- /scripts/collectstatic.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd examples/simple/ 3 | ./manage.py collectstatic --noinput --settings=settings.dev "$@" 4 | -------------------------------------------------------------------------------- /scripts/compile_messages.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | echo 'Compiling messages for django-dummy-thumbnails...' 3 | cd src/debug_toolbar_force/ 4 | django-admin.py compilemessages -l de 5 | django-admin.py compilemessages -l nl 6 | django-admin.py compilemessages -l ru 7 | 8 | echo 'Compiling messages for example projects...' 9 | cd ../../examples/simple/ 10 | django-admin.py compilemessages -l de 11 | django-admin.py compilemessages -l nl 12 | django-admin.py compilemessages -l ru 13 | -------------------------------------------------------------------------------- /scripts/compile_requirements.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd examples/requirements/ 3 | pip-compile base.in "$@" 4 | pip-compile code_style.in "$@" 5 | pip-compile common.in "$@" 6 | pip-compile coreapi_coreschema.in "$@" 7 | pip-compile debug.in "$@" 8 | pip-compile deployment.in "$@" 9 | pip-compile dev.in "$@" 10 | pip-compile django_2_2.in "$@" 11 | pip-compile django_2_2_and_elastic_6x.in "$@" 12 | pip-compile django_2_2_and_elastic_7x.in "$@" 13 | pip-compile django_3_1.in "$@" 14 | pip-compile django_3_1_and_elastic_6x.in "$@" 15 | pip-compile django_3_1_and_elastic_7x.in "$@" 16 | pip-compile django_3_2.in "$@" 17 | pip-compile django_3_2_and_elastic_6x.in "$@" 18 | pip-compile django_3_2_and_elastic_7x.in "$@" 19 | pip-compile docs.in "$@" 20 | pip-compile documentation.in "$@" 21 | pip-compile elastic.in "$@" 22 | pip-compile elastic_6x.in "$@" 23 | pip-compile elastic_7x.in "$@" 24 | pip-compile elastic_docker.in "$@" 25 | pip-compile test.in "$@" 26 | pip-compile testing.in "$@" 27 | -------------------------------------------------------------------------------- /scripts/coverage.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | coverage html 3 | -------------------------------------------------------------------------------- /scripts/create_dirs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | mkdir -p examples/logs/ 4 | mkdir -p examples/db/ 5 | mkdir -p examples/tmp/ 6 | mkdir -p var/ 7 | -------------------------------------------------------------------------------- /scripts/create_index.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd examples/simple/ 3 | ./manage.py search_index --create -f --settings=settings.dev "$@" 4 | #./manage.py search_index --populate -f "$@" 5 | -------------------------------------------------------------------------------- /scripts/create_test_data.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd examples/simple/ 3 | ./manage.py books_create_test_data --traceback -v 3 "$@" 4 | -------------------------------------------------------------------------------- /scripts/delete_index.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd examples/simple/ 3 | ./manage.py search_index --delete -f --settings=settings.dev "$@" 4 | -------------------------------------------------------------------------------- /scripts/dist.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | python setup.py sdist bdist_wheel 3 | -------------------------------------------------------------------------------- /scripts/elasticsearch_docker_start.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | version="6.3.2" 3 | port="9200" 4 | if [[ $1 == "--version" ]] 5 | then 6 | version="$2" 7 | shift 8 | shift 9 | args="$@" 10 | else 11 | version="6.3.2" 12 | args="$@" 13 | fi 14 | 15 | echo "Starting elasticsearch version $version." 16 | echo "If you wish to start a different version, provide --version {version} argument." 17 | echo " Example: --version 6.4.0" 18 | 19 | if [[ $args ]] 20 | then 21 | docker pull docker.elastic.co/elasticsearch/elasticsearch:"$version" 22 | docker run -p "$port:$port" -e "discovery.type=single-node" -e "xpack.security.enabled=false" docker.elastic.co/elasticsearch/elasticsearch:"$version" 23 | else 24 | docker pull docker.elastic.co/elasticsearch/elasticsearch:"$version" 25 | docker run -p "$port:$port" -e "discovery.type=single-node" -e "xpack.security.enabled=false" docker.elastic.co/elasticsearch/elasticsearch:"$version" 26 | fi 27 | -------------------------------------------------------------------------------- /scripts/elasticsearch_remove_all_indexes.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd examples/simple/ 3 | ./manage.py elasticsearch_remove_indexes --with-protected --settings=settings.dev "$@" 4 | -------------------------------------------------------------------------------- /scripts/elasticsearch_start.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | sudo service elasticsearch start 3 | sudo service kibana start 4 | -------------------------------------------------------------------------------- /scripts/elasticsearch_stop.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | sudo service elasticsearch stop 3 | sudo service kibana stop 4 | -------------------------------------------------------------------------------- /scripts/free_ports.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | sudo fuser -n tcp -k 9200 3 | sudo fuser -n tcp -k 8000 4 | sudo fuser -n tcp -k 5601 5 | -------------------------------------------------------------------------------- /scripts/frontend.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd examples/frontend/ 3 | yarn dev 4 | -------------------------------------------------------------------------------- /scripts/install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | pip install -r examples/requirements/dev.txt 3 | python setup.py develop 4 | mkdir -p examples/logs examples/db examples/media examples/media/static 5 | python examples/simple/manage.py collectstatic --noinput 6 | python examples/simple/manage.py migrate --noinput 7 | -------------------------------------------------------------------------------- /scripts/isort.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | reset 3 | isort -rc src/ --diff 4 | -------------------------------------------------------------------------------- /scripts/make_messages.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | echo 'Making messages for django-elasticsearch-dsl-drf...' 3 | cd src/django_elasticsearch_dsl_drf/ 4 | django-admin.py makemessages -l de 5 | django-admin.py makemessages -l nl 6 | django-admin.py makemessages -l ru 7 | 8 | echo 'Making messages for example projects...' 9 | cd ../../examples/simple/ 10 | django-admin.py makemessages -l de 11 | django-admin.py makemessages -l nl 12 | django-admin.py makemessages -l ru 13 | -------------------------------------------------------------------------------- /scripts/make_pypi_long_description.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | python setup.py --long-description > build/long_description.rst 3 | -------------------------------------------------------------------------------- /scripts/make_release.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ./scripts/uninstall.sh 3 | ./scripts/clean_up.sh 4 | python setup.py register 5 | python setup.py sdist bdist_wheel 6 | twine upload dist/* 7 | -------------------------------------------------------------------------------- /scripts/makemigrations.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd examples/simple/ 3 | ./manage.py makemigrations --settings=settings.dev "$@" 4 | -------------------------------------------------------------------------------- /scripts/manage.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd examples/simple/ 3 | ./manage.py "$@" --settings=settings.dev 4 | -------------------------------------------------------------------------------- /scripts/migrate.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd examples/simple/ 3 | ./manage.py migrate --settings=settings.dev "$@" 4 | -------------------------------------------------------------------------------- /scripts/prepare_docs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cat README.rst docs/documentation.rst.distrib > docs/index.rst 3 | cat CHANGELOG.rst > docs/changelog.rst 4 | cat examples/frontend/README.rst > docs/frontend_demo.rst 5 | -------------------------------------------------------------------------------- /scripts/prepare_project.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cp examples/simple/settings/__init__.example examples/simple/settings/__init__.py 3 | cp examples/simple/settings/local_settings.example examples/simple/settings/local_settings.py 4 | 5 | mkdir -p examples/db 6 | mkdir -p examples/logs 7 | 8 | cd examples/simple 9 | 10 | ./manage.py migrate 11 | 12 | ./manage.py books_create_test_data --number=10 13 | -------------------------------------------------------------------------------- /scripts/pycodestyle.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | reset 3 | pycodestyle src/django_elasticsearch_dsl_drf/ --exclude migrations,south_migrations 4 | -------------------------------------------------------------------------------- /scripts/pycodestyle_example.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | reset 3 | pycodestyle examples/simple/ --exclude examples/simple/wsgi.py,examples/simple/books/migrations/,examples/simple/books/tests/, 4 | -------------------------------------------------------------------------------- /scripts/pylint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | reset 3 | pylint src/django_elasticsearch_dsl_drf/ 4 | -------------------------------------------------------------------------------- /scripts/pylint_example.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | pylint examples/simple/ 3 | -------------------------------------------------------------------------------- /scripts/rebuild_docs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | rm docs/django_elasticsearch_dsl_drf*.rst 3 | rm -rf builddocs/ 4 | sphinx-apidoc src/django_elasticsearch_dsl_drf --full -o docs -H 'django-elasticsearch-dsl-drf' -A 'Artur Barseghyan ' -V '0.1' -f -d 20 5 | cp docs/conf.py.distrib docs/conf.py 6 | 7 | ./scripts/build_docs.sh 8 | -------------------------------------------------------------------------------- /scripts/rebuild_index.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd examples/simple/ 3 | ./manage.py search_index --rebuild -f --settings=settings.dev "$@" 4 | 5 | -------------------------------------------------------------------------------- /scripts/reinstall.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | reset 3 | ./scripts/uninstall.sh 4 | ./scripts/install.sh -------------------------------------------------------------------------------- /scripts/runserver.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd examples/simple/ 3 | server="0.0.0.0" 4 | port="8000" 5 | if [[ $1 == "--port" ]] 6 | then 7 | port="$2" 8 | shift 9 | shift 10 | args="$@" 11 | else 12 | port="8000" 13 | args="$@" 14 | fi 15 | 16 | #./manage.py runserver "$server:$port" --traceback -v 3 "$args" 17 | 18 | if [[ $args ]] 19 | then 20 | ./manage.py runserver "$server:$port" --traceback -v 3 "$args" 21 | else 22 | ./manage.py runserver "$server:$port" --traceback -v 3 "$@" 23 | fi 24 | -------------------------------------------------------------------------------- /scripts/runtests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | xvfb-run python runtests.py "$@" 3 | -------------------------------------------------------------------------------- /scripts/shell.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd examples/simple/ 3 | ./manage.py shell --traceback -v 3 --settings=settings.dev "$@" 4 | -------------------------------------------------------------------------------- /scripts/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | reset 3 | #./scripts/uninstall.sh 4 | #./scripts/install.sh 5 | python examples/simple/manage.py test django_elasticsearch_dsl_drf.tests.test_suggesters --traceback -v 3 --settings=settings.testing 6 | -------------------------------------------------------------------------------- /scripts/tox.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | xvfb-run python toxtests.py 3 | -------------------------------------------------------------------------------- /scripts/uninstall.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | pip uninstall django-elasticsearch-dsl-drf -y 3 | rm build -rf 4 | rm dist -rf 5 | rm -rf src/django_elasticsearch_dsl_drf.egg-info 6 | rm -rf src/django-elasticsearch-dsl-drf.egg-info 7 | rm builddocs.zip 8 | rm builddocs/ -rf 9 | -------------------------------------------------------------------------------- /scripts/update_index.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd examples/simple/ 3 | ./manage.py search_index --populate -f --settings=settings.dev "$@" 4 | -------------------------------------------------------------------------------- /scripts/upgrade_requirements.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd examples/requirements/ 3 | pip-compile base.in "$@" --upgrade 4 | pip-compile code_style.in "$@" --upgrade 5 | pip-compile common.in "$@" --upgrade 6 | pip-compile coreapi_coreschema.in "$@" --upgrade 7 | pip-compile debug.in "$@" --upgrade 8 | pip-compile deployment.in "$@" --upgrade 9 | pip-compile dev.in "$@" --upgrade 10 | pip-compile django_2_2.in "$@" --upgrade 11 | pip-compile django_2_2_and_elastic_6x.in "$@" --upgrade 12 | pip-compile django_2_2_and_elastic_7x.in "$@" --upgrade 13 | pip-compile django_3_1.in "$@" --upgrade 14 | pip-compile django_3_1_and_elastic_6x.in "$@" --upgrade 15 | pip-compile django_3_1_and_elastic_7x.in "$@" --upgrade 16 | pip-compile django_3_2.in "$@" --upgrade 17 | pip-compile django_3_2_and_elastic_6x.in "$@" --upgrade 18 | pip-compile django_3_2_and_elastic_7x.in "$@" --upgrade 19 | pip-compile docs.in "$@" --upgrade 20 | pip-compile documentation.in "$@" --upgrade 21 | pip-compile elastic.in "$@" --upgrade 22 | pip-compile elastic_6x.in "$@" --upgrade 23 | pip-compile elastic_7x.in "$@" --upgrade 24 | pip-compile test.in "$@" --upgrade 25 | pip-compile testing.in "$@" --upgrade 26 | -------------------------------------------------------------------------------- /scripts/vagrant_start.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd vagrant 3 | vagrant up 4 | -------------------------------------------------------------------------------- /scripts/vagrant_stop.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd vagrant 3 | vagrant suspend 4 | -------------------------------------------------------------------------------- /scripts/yarn_install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd examples/frontend/ 3 | yarn install 4 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal = 1 -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Integrate Elasticsearch DSL with Django REST framework. 3 | """ 4 | 5 | __title__ = 'django-elasticsearch-dsl-drf' 6 | __version__ = '0.22.5' 7 | __author__ = 'Artur Barseghyan ' 8 | __copyright__ = '2017-2022 Artur Barseghyan' 9 | __license__ = 'GPL 2.0/LGPL 2.1' 10 | 11 | 12 | from django_nine import versions 13 | 14 | if versions.DJANGO_LTE_3_1: 15 | __all__ = ('default_app_config',) 16 | default_app_config = 'django_elasticsearch_dsl_drf.apps.Config' 17 | -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/analyzers.py: -------------------------------------------------------------------------------- 1 | """ 2 | Analyzers. 3 | """ 4 | from elasticsearch_dsl import analyzer 5 | from elasticsearch_dsl.analysis import token_filter 6 | 7 | __title__ = 'django_elasticsearch_dsl_drf.analyzers' 8 | __author__ = 'Artur Barseghyan ' 9 | __copyright__ = '2017-2020 Artur Barseghyan' 10 | __license__ = 'GPL 2.0/LGPL 2.1' 11 | __all__ = ( 12 | 'edge_ngram_completion_filter', 13 | 'edge_ngram_completion', 14 | ) 15 | 16 | edge_ngram_completion_filter = token_filter( 17 | 'edge_ngram_completion_filter', 18 | type="edge_ngram", 19 | min_gram=1, 20 | max_gram=20 21 | ) 22 | 23 | 24 | edge_ngram_completion = analyzer( 25 | "edge_ngram_completion", 26 | tokenizer="standard", 27 | filter=["lowercase", edge_ngram_completion_filter] 28 | ) 29 | -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/apps.py: -------------------------------------------------------------------------------- 1 | """ 2 | Apps. 3 | """ 4 | 5 | from django.apps import AppConfig 6 | 7 | __title__ = 'django_elasticsearch_dsl_drf.apps' 8 | __author__ = 'Artur Barseghyan ' 9 | __copyright__ = '2017-2020 Artur Barseghyan' 10 | __license__ = 'GPL 2.0/LGPL 2.1' 11 | __all__ = ('Config',) 12 | 13 | 14 | class Config(AppConfig): 15 | """Config.""" 16 | 17 | name = 'django_elasticsearch_dsl_drf' 18 | label = 'django_elasticsearch_dsl_drf' 19 | -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/elasticsearch_helpers.py: -------------------------------------------------------------------------------- 1 | from django.conf import settings 2 | from elasticsearch import Elasticsearch 3 | 4 | __all__ = ( 5 | "get_all_indices", 6 | "delete_all_indices", 7 | ) 8 | 9 | 10 | def get_all_indices(with_protected=False): 11 | """Get all indices. 12 | Args: 13 | with_protected (bool): 14 | Returns: 15 | list: List of indices. 16 | """ 17 | es = Elasticsearch(**settings.ELASTICSEARCH_DSL["default"]) 18 | _indices = es.indices.get_alias("*").items() 19 | if with_protected: 20 | return [_i for _i, _o in _indices] 21 | else: 22 | return [_i for _i, _o in _indices if not _i.startswith(".")] 23 | 24 | 25 | def delete_all_indices(with_protected=False): 26 | """Delete all indices. 27 | Args: 28 | with_protected (bool): 29 | Returns: 30 | tuple: Tuple of two lists with removed and errored indices. 31 | """ 32 | es = Elasticsearch(**settings.ELASTICSEARCH_DSL["default"]) 33 | _indices = get_all_indices(with_protected=with_protected) 34 | _ok = [] 35 | _fail = [] 36 | for _i in _indices: 37 | try: 38 | _res = es.indices.delete(_i) 39 | except Exception as err: 40 | _fail.append(_i) 41 | if _res and isinstance(_res, dict) and _res.get("acknowledged", False): 42 | _ok.append(_i) 43 | return _ok, _fail 44 | -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/fields/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Fields. 3 | """ 4 | 5 | from .common import ( 6 | BooleanField, 7 | CharField, 8 | DateField, 9 | FloatField, 10 | IntegerField, 11 | IPAddressField, 12 | ) 13 | from .nested_fields import ( 14 | GeoPointField, 15 | GeoShapeField, 16 | ListField, 17 | NestedField, 18 | ObjectField, 19 | ) 20 | 21 | __title__ = 'django_elasticsearch_dsl_drf.fields' 22 | __author__ = 'Artur Barseghyan ' 23 | __copyright__ = '2017-2020 Artur Barseghyan' 24 | __license__ = 'GPL 2.0/LGPL 2.1' 25 | __all__ = ( 26 | 'BooleanField', 27 | 'CharField', 28 | 'DateField', 29 | 'FloatField', 30 | 'GeoPointField', 31 | 'GeoShapeField', 32 | 'IntegerField', 33 | 'IPAddressField', 34 | 'ListField', 35 | 'NestedField', 36 | 'ObjectField', 37 | ) 38 | -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/fields/helpers.py: -------------------------------------------------------------------------------- 1 | """ 2 | Helpers. 3 | """ 4 | from elasticsearch_dsl.utils import AttrDict, AttrList 5 | 6 | __title__ = 'django_elasticsearch_dsl_drf.fields.helpers' 7 | __author__ = 'Artur Barseghyan ' 8 | __copyright__ = '2017-2020 Artur Barseghyan' 9 | __license__ = 'GPL 2.0/LGPL 2.1' 10 | __all__ = ('to_representation',) 11 | 12 | 13 | def to_representation(value): 14 | """To representation.""" 15 | if isinstance(value, AttrDict): 16 | return value.to_dict() 17 | if isinstance(value, AttrList): 18 | _value = [to_representation(__v) for __v in value] 19 | return _value 20 | # If approach above doesn't work, replace it with the code below 21 | # try: 22 | # _value = list(value) 23 | # json.dumps(_value) 24 | # return _value 25 | # except TypeError: 26 | # _value = [to_representation(__v) for __v in value] 27 | # return _value 28 | return value 29 | -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/fields/nested_fields.py: -------------------------------------------------------------------------------- 1 | """ 2 | Nested fields. 3 | """ 4 | 5 | from rest_framework.serializers import Field 6 | from .helpers import to_representation 7 | 8 | __title__ = 'django_elasticsearch_dsl_drf.fields.nested_fields' 9 | __author__ = 'Artur Barseghyan ' 10 | __copyright__ = '2017-2020 Artur Barseghyan' 11 | __license__ = 'GPL 2.0/LGPL 2.1' 12 | __all__ = ( 13 | 'GeoPointField', 14 | 'GeoShapeField', 15 | 'NestedField', 16 | 'ObjectField', 17 | 'ListField', 18 | ) 19 | 20 | 21 | class ObjectField(Field): 22 | """Object field.""" 23 | 24 | def get_value(self, dictionary): 25 | """Get value.""" 26 | value = super(ObjectField, self).get_value(dictionary) 27 | 28 | return to_representation(value) 29 | 30 | def to_internal_value(self, data): 31 | """To internal value.""" 32 | return data 33 | 34 | def to_representation(self, value): 35 | """To representation.""" 36 | return to_representation(value) 37 | 38 | 39 | class NestedField(ObjectField): 40 | """Nested field.""" 41 | 42 | 43 | class GeoPointField(ObjectField): 44 | """Geo point field.""" 45 | 46 | 47 | class GeoShapeField(ObjectField): 48 | """Geo shape field.""" 49 | 50 | 51 | class ListField(Field): 52 | """List field.""" 53 | 54 | def get_value(self, dictionary): 55 | """Get value.""" 56 | value = super(ListField, self).get_value(dictionary) 57 | return to_representation(value) 58 | 59 | def to_internal_value(self, data): 60 | """To internal value.""" 61 | return data 62 | 63 | def to_representation(self, value): 64 | """To representation.""" 65 | return to_representation(value) 66 | -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/filter_backends/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | All filter backends. 3 | """ 4 | 5 | from .faceted_search import ( 6 | FacetedSearchFilterBackend, 7 | FacetedFilterSearchFilterBackend 8 | ) 9 | from .filtering import ( 10 | FilteringFilterBackend, 11 | GeoSpatialFilteringFilterBackend, 12 | IdsFilterBackend, 13 | NestedFilteringFilterBackend, 14 | PostFilterFilteringFilterBackend, 15 | ) 16 | from .ordering import ( 17 | DefaultOrderingFilterBackend, 18 | GeoSpatialOrderingFilterBackend, 19 | OrderingFilterBackend, 20 | ) 21 | from .search import ( 22 | BaseSearchFilterBackend, 23 | CompoundSearchFilterBackend, 24 | MultiMatchSearchFilterBackend, 25 | SearchFilterBackend, 26 | SimpleQueryStringSearchFilterBackend, 27 | ) 28 | from .source import SourceBackend 29 | from .suggester import ( 30 | FunctionalSuggesterFilterBackend, 31 | SuggesterFilterBackend, 32 | ) 33 | from .highlight import HighlightBackend 34 | 35 | __title__ = 'django_elasticsearch_dsl_drf.filter_backends' 36 | __author__ = 'Artur Barseghyan ' 37 | __copyright__ = '2017-2020 Artur Barseghyan' 38 | __license__ = 'GPL 2.0/LGPL 2.1' 39 | -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/filter_backends/aggregations/__init__.py: -------------------------------------------------------------------------------- 1 | # """ 2 | # Aggregations filtering backends. 3 | # """ 4 | # 5 | # from .bucket_aggregations import * 6 | # from .metrics_aggregations import * 7 | # from .pipeline_aggregations import * 8 | # 9 | # __title__ = 'django_elasticsearch_dsl_drf.filter_backends.suggester' 10 | # __author__ = 'Artur Barseghyan ' 11 | # __copyright__ = '2017-2020 Artur Barseghyan' 12 | # __license__ = 'GPL 2.0/LGPL 2.1' 13 | # __all__ = ( 14 | # 'BucketAggregationsFilterBackend', 15 | # 'MetricsAggregationsFilterBackend', 16 | # 'PipelineAggregationsFilterBackend', 17 | # ) 18 | -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/filter_backends/aggregations/bucket_aggregations.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/django-elasticsearch-dsl-drf/d83900f2c92b38b00423065795b146434c5a5bf7/src/django_elasticsearch_dsl_drf/filter_backends/aggregations/bucket_aggregations.py -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/filter_backends/aggregations/metrics_aggregations.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/django-elasticsearch-dsl-drf/d83900f2c92b38b00423065795b146434c5a5bf7/src/django_elasticsearch_dsl_drf/filter_backends/aggregations/metrics_aggregations.py -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/filter_backends/aggregations/pipeline_aggregations.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/django-elasticsearch-dsl-drf/d83900f2c92b38b00423065795b146434c5a5bf7/src/django_elasticsearch_dsl_drf/filter_backends/aggregations/pipeline_aggregations.py -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/filter_backends/filtering/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Term level filtering and ``post_filter`` backends. 3 | """ 4 | 5 | from .common import FilteringFilterBackend 6 | from .geo_spatial import GeoSpatialFilteringFilterBackend 7 | from .ids import IdsFilterBackend 8 | from .nested import NestedFilteringFilterBackend 9 | from .post_filter import PostFilterFilteringFilterBackend 10 | 11 | __title__ = 'django_elasticsearch_dsl_drf.filter_backends.filtering' 12 | __author__ = 'Artur Barseghyan ' 13 | __copyright__ = '2017-2020 Artur Barseghyan' 14 | __license__ = 'GPL 2.0/LGPL 2.1' 15 | __all__ = ( 16 | 'FilteringFilterBackend', 17 | 'GeoSpatialFilteringFilterBackend', 18 | 'IdsFilterBackend', 19 | 'NestedFilteringFilterBackend', 20 | 'PostFilterFilteringFilterBackend', 21 | ) 22 | -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/filter_backends/ordering/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Ordering backends. 3 | """ 4 | 5 | from .common import DefaultOrderingFilterBackend, OrderingFilterBackend 6 | from .geo_spatial import GeoSpatialOrderingFilterBackend 7 | 8 | __title__ = 'django_elasticsearch_dsl_drf.filter_backends.ordering' 9 | __author__ = 'Artur Barseghyan ' 10 | __copyright__ = '2017-2020 Artur Barseghyan' 11 | __license__ = 'GPL 2.0/LGPL 2.1' 12 | __all__ = ( 13 | 'DefaultOrderingFilterBackend', 14 | 'GeoSpatialOrderingFilterBackend', 15 | 'OrderingFilterBackend', 16 | ) 17 | -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/filter_backends/search/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Search filter backends. 3 | """ 4 | 5 | from .base import BaseSearchFilterBackend 6 | from .compound import CompoundSearchFilterBackend 7 | from .historical import SearchFilterBackend 8 | from .multi_match import MultiMatchSearchFilterBackend 9 | from .simple_query_string import SimpleQueryStringSearchFilterBackend 10 | 11 | __title__ = 'django_elasticsearch_dsl_drf.filter_backends.search' 12 | __author__ = 'Artur Barseghyan ' 13 | __copyright__ = '2017-2020 Artur Barseghyan' 14 | __license__ = 'GPL 2.0/LGPL 2.1' 15 | __all__ = ( 16 | 'BaseSearchFilterBackend', 17 | 'CompoundSearchFilterBackend', 18 | 'MultiMatchSearchFilterBackend', 19 | 'SearchFilterBackend', 20 | 'SimpleQueryStringSearchFilterBackend', 21 | ) 22 | -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/filter_backends/search/compound.py: -------------------------------------------------------------------------------- 1 | """Compound search backend.""" 2 | 3 | from .base import BaseSearchFilterBackend 4 | from .query_backends import ( 5 | MatchQueryBackend, 6 | NestedQueryBackend, 7 | ) 8 | 9 | __title__ = 'django_elasticsearch_dsl_drf.filter_backends.search.compound' 10 | __author__ = 'Artur Barseghyan ' 11 | __copyright__ = '2017-2020 Artur Barseghyan' 12 | __license__ = 'GPL 2.0/LGPL 2.1' 13 | __all__ = ( 14 | 'CompoundSearchFilterBackend', 15 | ) 16 | 17 | 18 | class CompoundSearchFilterBackend(BaseSearchFilterBackend): 19 | """Compound search backend.""" 20 | 21 | query_backends = [ 22 | MatchQueryBackend, 23 | NestedQueryBackend, 24 | ] 25 | -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/filter_backends/search/multi_match.py: -------------------------------------------------------------------------------- 1 | """Multi match search filter backend.""" 2 | import logging 3 | 4 | from ...constants import MATCHING_OPTION_MUST 5 | from .base import BaseSearchFilterBackend 6 | from .query_backends import ( 7 | MultiMatchQueryBackend, 8 | ) 9 | 10 | LOGGER = logging.getLogger(__name__) 11 | 12 | 13 | __title__ = 'django_elasticsearch_dsl_drf.filter_backends.search.multi_match' 14 | __author__ = 'Artur Barseghyan ' 15 | __copyright__ = '2017-2020 Artur Barseghyan' 16 | __license__ = 'GPL 2.0/LGPL 2.1' 17 | __all__ = ( 18 | 'MultiMatchSearchFilterBackend', 19 | ) 20 | 21 | 22 | class MultiMatchSearchFilterBackend(BaseSearchFilterBackend): 23 | """Multi match search filter backend.""" 24 | 25 | search_param = 'search_multi_match' 26 | 27 | matching = MATCHING_OPTION_MUST 28 | 29 | query_backends = [ 30 | MultiMatchQueryBackend, 31 | ] 32 | -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/filter_backends/search/query_backends/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Search query backends. 3 | """ 4 | 5 | from .base import BaseSearchQueryBackend 6 | from .match import MatchQueryBackend 7 | from .match_phrase import MatchPhraseQueryBackend 8 | from .match_phrase_prefix import MatchPhrasePrefixQueryBackend 9 | from .multi_match import MultiMatchQueryBackend 10 | from .nested import NestedQueryBackend 11 | from .simple_query_string import SimpleQueryStringQueryBackend 12 | 13 | __title__ = 'django_elasticsearch_dsl_drf.filter_backends.search.' \ 14 | 'query_backends' 15 | __author__ = 'Artur Barseghyan ' 16 | __copyright__ = '2017-2020 Artur Barseghyan' 17 | __license__ = 'GPL 2.0/LGPL 2.1' 18 | __all__ = ( 19 | 'BaseSearchQueryBackend', 20 | 'MatchQueryBackend', 21 | 'MatchPhraseQueryBackend', 22 | 'MatchPhrasePrefixQueryBackend', 23 | 'MultiMatchQueryBackend', 24 | 'NestedQueryBackend', 25 | 'SimpleQueryStringQueryBackend', 26 | ) 27 | -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/filter_backends/search/query_backends/base.py: -------------------------------------------------------------------------------- 1 | __title__ = 'django_elasticsearch_dsl_drf.filter_backends.search.' \ 2 | 'query_backends.base' 3 | __author__ = 'Artur Barseghyan ' 4 | __copyright__ = '2017-2020 Artur Barseghyan' 5 | __license__ = 'GPL 2.0/LGPL 2.1' 6 | __all__ = ('BaseSearchQueryBackend',) 7 | 8 | 9 | class BaseSearchQueryBackend(object): 10 | """Search query backend.""" 11 | 12 | @classmethod 13 | def construct_search(cls, request, view, search_backend): 14 | """Construct search. 15 | 16 | :param request: 17 | :param view: 18 | :param search_backend: 19 | :return: 20 | """ 21 | raise NotImplementedError( 22 | "You should implement `construct_search` method in your {} class" 23 | "".format(cls.__name__) 24 | ) 25 | -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/filter_backends/search/query_string.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/django-elasticsearch-dsl-drf/d83900f2c92b38b00423065795b146434c5a5bf7/src/django_elasticsearch_dsl_drf/filter_backends/search/query_string.py -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/filter_backends/search/simple_query_string.py: -------------------------------------------------------------------------------- 1 | """Simple query string search filter backend.""" 2 | import logging 3 | 4 | from ...constants import MATCHING_OPTION_MUST 5 | from .base import BaseSearchFilterBackend 6 | from .query_backends import ( 7 | SimpleQueryStringQueryBackend, 8 | ) 9 | 10 | LOGGER = logging.getLogger(__name__) 11 | 12 | 13 | __title__ = 'django_elasticsearch_dsl_drf.filter_backends.search.' \ 14 | 'simple_query_string' 15 | __author__ = 'Artur Barseghyan ' 16 | __copyright__ = '2017-2020 Artur Barseghyan' 17 | __license__ = 'GPL 2.0/LGPL 2.1' 18 | __all__ = ( 19 | 'SimpleQueryStringSearchFilterBackend', 20 | ) 21 | 22 | 23 | class SimpleQueryStringSearchFilterBackend(BaseSearchFilterBackend): 24 | """Simple query string search filter backend.""" 25 | 26 | search_param = 'search_simple_query_string' 27 | 28 | matching = MATCHING_OPTION_MUST 29 | 30 | query_backends = [ 31 | SimpleQueryStringQueryBackend, 32 | ] 33 | -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/filter_backends/suggester/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Suggester filtering backends. 3 | """ 4 | 5 | from .functional import FunctionalSuggesterFilterBackend 6 | from .native import SuggesterFilterBackend 7 | 8 | __title__ = 'django_elasticsearch_dsl_drf.filter_backends.suggester' 9 | __author__ = 'Artur Barseghyan ' 10 | __copyright__ = '2017-2020 Artur Barseghyan' 11 | __license__ = 'GPL 2.0/LGPL 2.1' 12 | __all__ = ( 13 | 'SuggesterFilterBackend', 14 | 'FunctionalSuggesterFilterBackend', 15 | ) 16 | -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/management/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/django-elasticsearch-dsl-drf/d83900f2c92b38b00423065795b146434c5a5bf7/src/django_elasticsearch_dsl_drf/management/__init__.py -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/management/commands/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/django-elasticsearch-dsl-drf/d83900f2c92b38b00423065795b146434c5a5bf7/src/django_elasticsearch_dsl_drf/management/commands/__init__.py -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/management/commands/elasticsearch_remove_indexes.py: -------------------------------------------------------------------------------- 1 | from django.core.management.base import BaseCommand 2 | 3 | from ...elasticsearch_helpers import delete_all_indices, get_all_indices 4 | 5 | 6 | class Command(BaseCommand): 7 | help = 'Remove all indexes from Elasticsearch' 8 | 9 | def add_arguments(self, parser): 10 | # Named (optional) arguments 11 | parser.add_argument( 12 | '--dry-run', 13 | action='store_true', 14 | dest='dry_run', 15 | default=False, 16 | help='Dry-run (no db writes)', 17 | ) 18 | parser.add_argument( 19 | '--with-protected', 20 | action='store_true', 21 | dest='with_protected', 22 | default=False, 23 | help='Including protected (for instance, kibana) indexes', 24 | ) 25 | 26 | def handle(self, *args, **options): 27 | dry_run = options.get('dry_run', False) 28 | with_protected = options.get('with_protected', False) 29 | if dry_run: 30 | indices = get_all_indices(with_protected=with_protected) 31 | print("The following indexes will be removed: {}".format(indices)) 32 | else: 33 | indices, errors = delete_all_indices(with_protected=with_protected) 34 | print("The following indexes are removed: {}".format(indices)) 35 | print( 36 | "The following indexes could not be removed: {}".format(errors) 37 | ) 38 | -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/pip_helpers.py: -------------------------------------------------------------------------------- 1 | """ 2 | Pip helpers module. 3 | """ 4 | import subprocess 5 | import sys 6 | 7 | __title__ = 'django_elasticsearch_dsl_drf.tests.pip_helpers' 8 | __author__ = 'Artur Barseghyan ' 9 | __copyright__ = '2017-2020 Artur Barseghyan' 10 | __license__ = 'GPL 2.0/LGPL 2.1' 11 | __all__ = ( 12 | 'check_if_installed', 13 | 'get_installed_packages', 14 | ) 15 | 16 | 17 | def get_installed_packages(with_versions=False): 18 | """Get installed packages. 19 | 20 | :param with_versions: If set to True, returned with versions. 21 | :type with_versions: bool 22 | :return: 23 | :rtype: list 24 | """ 25 | reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze']) 26 | if with_versions: 27 | return set([tuple(r.decode().split('==')) for r in reqs.split()]) 28 | else: 29 | return set([r.decode().split('==')[0] for r in reqs.split()]) 30 | 31 | 32 | def check_if_installed(package, installed_packages=None): 33 | """Check if package is installed. 34 | 35 | :param package: 36 | :param installed_packages: 37 | :type package: str 38 | :type installed_packages: iterable 39 | :return: 40 | :rtype: bool 41 | """ 42 | if installed_packages is None: 43 | installed_packages = get_installed_packages(with_versions=False) 44 | return package in installed_packages 45 | -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/barseghyanartur/django-elasticsearch-dsl-drf/d83900f2c92b38b00423065795b146434c5a5bf7/src/django_elasticsearch_dsl_drf/tests/__init__.py -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/tests/test_utils.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test utils. 3 | """ 4 | 5 | from __future__ import absolute_import 6 | 7 | import unittest 8 | 9 | from django.urls import reverse 10 | from django.core.management import call_command 11 | 12 | import pytest 13 | 14 | from rest_framework import status 15 | 16 | from .base import BaseRestFrameworkTestCase 17 | 18 | __title__ = 'django_elasticsearch_dsl_drf.tests.test_utils' 19 | __author__ = 'Artur Barseghyan ' 20 | __copyright__ = '2017-2020 Artur Barseghyan' 21 | __license__ = 'GPL 2.0/LGPL 2.1' 22 | __all__ = ( 23 | 'TestUtils', 24 | ) 25 | 26 | 27 | @pytest.mark.django_db 28 | class TestUtils(BaseRestFrameworkTestCase): 29 | """Test utils.""" 30 | 31 | pytestmark = pytest.mark.django_db 32 | 33 | @classmethod 34 | def setUpClass(cls): 35 | super(TestUtils, cls).setUpClass() 36 | 37 | cls.sleep() 38 | call_command('search_index', '--rebuild', '-f') 39 | 40 | def _list_results(self): 41 | """List results.""" 42 | self.authenticate() 43 | 44 | url = reverse('bookdocument_no_records-list', kwargs={}) 45 | 46 | # Make request 47 | response = self.client.get(url, {}) 48 | self.assertEqual( 49 | response.status_code, 50 | status.HTTP_200_OK 51 | ) 52 | 53 | # Should contain no results 54 | self.assertEqual(response.data['results'], []) 55 | self.assertEqual(response.data['count'], 0) 56 | self.assertEqual(response.data['next'], None) 57 | self.assertEqual(response.data['previous'], None) 58 | 59 | def test_list_results(self): 60 | """Test list results.""" 61 | return self._list_results() 62 | 63 | 64 | if __name__ == '__main__': 65 | unittest.main() 66 | -------------------------------------------------------------------------------- /src/django_elasticsearch_dsl_drf/utils.py: -------------------------------------------------------------------------------- 1 | """ 2 | Utils. 3 | """ 4 | 5 | import datetime 6 | from elasticsearch_dsl.search import AggsProxy 7 | 8 | 9 | __title__ = 'django_elasticsearch_dsl_drf.utils' 10 | __author__ = 'Artur Barseghyan ' 11 | __copyright__ = '2017-2020 Artur Barseghyan' 12 | __license__ = 'GPL 2.0/LGPL 2.1' 13 | __all__ = ( 14 | 'DictionaryProxy', 15 | 'EmptySearch', 16 | ) 17 | 18 | 19 | class EmptySearch(object): 20 | """Empty Search.""" 21 | 22 | def __init__(self, *args, **kwargs): 23 | self.aggs = AggsProxy('') 24 | self._highlight = {} 25 | self._sort = [] 26 | self.total = 0 27 | 28 | def __len__(self): 29 | return 0 30 | 31 | def __iter__(self): 32 | return iter([]) 33 | 34 | def __getitem__(self, *args, **kwargs): 35 | return self 36 | 37 | def highlight(self, *args, **kwargs): 38 | return self 39 | 40 | def sort(self, *args, **kwargs): 41 | return self 42 | 43 | @property 44 | def hits(self): 45 | return self 46 | 47 | def execute(self, *args, **kwargs): 48 | return self 49 | 50 | def to_dict(self, *args, **kwargs): 51 | return {} 52 | 53 | 54 | class DictionaryProxy(object): 55 | """Dictionary proxy.""" 56 | 57 | def __init__(self, mapping, meta=None): 58 | self.__mapping = mapping 59 | self.meta = meta 60 | 61 | def __getattr__(self, item): 62 | if item == "meta": 63 | return self.meta 64 | val = self.__mapping.get(item, None) 65 | if isinstance(val, datetime.datetime) and not val.tzinfo: 66 | val = val.date() 67 | return val 68 | 69 | def to_dict(self): 70 | """To dict. 71 | 72 | :return: 73 | """ 74 | return self.__mapping 75 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = 3 | py{36,37,38,39}-django{22,31,32}-elasticsearch{6,7} 4 | 5 | [testenv] 6 | envlogdir= 7 | examples/logs/ 8 | examples/db/ 9 | examples/tmp/ 10 | passenv = * 11 | deps = 12 | django22: -r{toxinidir}/examples/requirements/django_2_2.txt 13 | django31: -r{toxinidir}/examples/requirements/django_3_1.txt 14 | django32: -r{toxinidir}/examples/requirements/django_3_2.txt 15 | elasticsearch6: -r{toxinidir}/examples/requirements/elastic_6x.txt 16 | elasticsearch7: -r{toxinidir}/examples/requirements/elastic_7x.txt 17 | ; coreapischema: -r{toxinidir}/examples/requirements/coreapi_coreschema.txt 18 | ; none: -r{toxinidir}/examples/requirements/none.txt 19 | commands = 20 | pip install -e . 21 | pytest 22 | ; {envpython} runtests.py {posargs} 23 | ; {envpython} examples/simple/manage.py test {posargs:django_elasticsearch_dsl_drf} --settings=settings.testing --traceback -v 3 24 | -------------------------------------------------------------------------------- /vagrant/README.rst: -------------------------------------------------------------------------------- 1 | Vagrant 2 | ------- 3 | Vagrant file for testing. 4 | 5 | Versions 6 | ~~~~~~~~ 7 | - Java 8 8 | - Elasticsearch 2.x 9 | - Kibana 4.6.x 10 | 11 | Installation 12 | ~~~~~~~~~~~~ 13 | Installing VirtualBox: 14 | 15 | .. code-block:: sh 16 | 17 | sudo apt-get install virtualbox 18 | 19 | Or on Mac Os: 20 | 21 | .. code-block:: sh 22 | 23 | brew cask install virtualbox 24 | 25 | Installing Vagrant: 26 | 27 | .. code-block:: sh 28 | 29 | sudo apt-get install vagrant 30 | sudo apt-get install virtualbox-dkms 31 | 32 | Or on Mac: 33 | 34 | .. code-block:: sh 35 | 36 | brew cask install vagrant 37 | brew cask install vagrant-manager 38 | 39 | Getting vagrant machine up: 40 | 41 | .. code-block:: sh 42 | 43 | vagrant box add precise32 http://files.vagrantup.com/precise32.box 44 | vagrant init precise32 45 | 46 | Running a Vagrant environment 47 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 48 | To start up: 49 | 50 | .. code-block:: sh 51 | 52 | vagrant up 53 | 54 | To shut down: 55 | 56 | .. code-block:: sh 57 | 58 | vagrant suspend 59 | 60 | Browsing Elasticsearch indexes 61 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 62 | A `head `_ plugin to browse 63 | Elasticsearch indexes has been installed. 64 | 65 | Just open the following link in your browser: 66 | 67 | .. code-block:: text 68 | 69 | http://localhost:9200/_plugin/head/ 70 | 71 | Kibana 72 | ~~~~~~ 73 | 74 | Just open the following link in your browser: 75 | 76 | .. code-block:: text 77 | 78 | http://localhost:5601/ 79 | --------------------------------------------------------------------------------