{"id":13788838,"url":"https://github.com/Taymindis/nginx-elastic-client","last_synced_at":"2025-05-12T03:30:47.006Z","repository":{"id":132372000,"uuid":"130675934","full_name":"Taymindis/nginx-elastic-client","owner":"Taymindis","description":"To structure your elastic client command in your nginx proxy for multiple elasticsearch server.","archived":false,"fork":false,"pushed_at":"2018-04-27T07:27:02.000Z","size":31,"stargazers_count":22,"open_issues_count":0,"forks_count":1,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-10T03:55:59.402Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Taymindis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-04-23T09:53:11.000Z","updated_at":"2023-08-31T12:50:08.000Z","dependencies_parsed_at":"2023-03-21T18:50:20.767Z","dependency_job_id":null,"html_url":"https://github.com/Taymindis/nginx-elastic-client","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Taymindis%2Fnginx-elastic-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Taymindis%2Fnginx-elastic-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Taymindis%2Fnginx-elastic-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Taymindis%2Fnginx-elastic-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Taymindis","download_url":"https://codeload.github.com/Taymindis/nginx-elastic-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253667942,"owners_count":21944943,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T21:00:54.449Z","updated_at":"2025-05-12T03:30:46.746Z","avatar_url":"https://github.com/Taymindis.png","language":"C","funding_links":[],"categories":["Third Party Modules"],"sub_categories":["C Modules"],"readme":"nginx-elastic-client\n====================\n\nTo structure your elastic client command in your nginx proxy for multiple elasticsearch server.\n\nTable of Contents\n=================\n\n* [Introduction](#introduction)\n* [Usage](#usage)\n* [Installation](#installation)\n* [Test](#test)\n* [Why need this](#why-need-this)\n* [Support](#support)\n* [Copyright \u0026 License](#copyright--license)\n\nIntroduction\n============\n\nnginx-elastic-client is a nginx module which allow to proxy to elastic server with given pre-defined/dynamic command.\n\n\nUsage\n=======\n### 0. Setup your elastic upstream\n```nginx\n# nginx.conf\n  upstream elastic_upstream {\n     server 127.0.0.1:9200;\n  }\n```\n\n\n### 1. Simple create index command, please noted that http method is defined inside command, it regardless what you called to nginx.\n```nginx\n# nginx.conf\n\nserver {\n    ....\n   location /test {\n        elastic_pass http://elastic_upstream;\n        elastic_send PUT /testindex/testdoc/100;\n        elastic_query '{\n            \"testname\": \"mytest\"            \n        }';\n    }\n}\n```\n\n\n### 2. If you don't want any command inside config, just pass ngixn variables to the elastic host, please setup the config below, you may refer the [nginx variables](https://gist.github.com/esfand/8262283)  for more details\n```nginx\n# nginx.conf\n\nserver {\n  ....\n  \n  location / {\n      elastic_pass http://elastic_upstream;\n      elastic_send $request_method $uri?$query_string; \n      elastic_query $request_body;\n  }\n}\n```\n\n\n### 3. Create index based on your args, for example /test?new_id=Staff1232\n```nginx\n# nginx.conf\n\nserver {\n    ....\n   location /test {\n        elastic_pass http://elastic_upstream;\n        elastic_send PUT /testindex/testdoc/$arg_new_id;\n        elastic_query '{\n            \"testname\": \"mytest-$arg_new_id\"            \n        }';\n    }\n}\n```\n\n\n### 4. search all\n```nginx\n# nginx.conf\n\nserver {\n    ....\n   location /test {\n        elastic_pass http://elastic_upstream;\n        elastic_send POST /testindex/testdoc/_search/;\n        elastic_query '{\"query\":\n           {\n            \"match_all\": {}\n           }\n        }';\n    }\n}\n```\n\n\n### 5. search all but group the docs by index.\n```nginx\n# nginx.conf\n\nserver {\n    ....\n     location /test {\n        elastic_pass http://elastic_upstream;\n        elastic_send POST /testindex/testdoc/_search?size=100 index_docs;\n        \n        elastic_query '{\"query\":\n           {\n            \"match_all\": {}\n           }\n        }';\n    }\n}\n```\n\n\n### 6. search all but skipmeta data, keep index, type, and id.\n```nginx\n# nginx.conf\n\nserver {\n    ....\n     location /test {\n        elastic_pass http://elastic_upstream;\n        elastic_send POST /testindex/testdoc/_search skipmeta;\n        \n        elastic_query '{\"query\":\n           {\n            \"match_all\": {}\n           }\n        }';\n    }\n}\n```\n\n\n### 7. search all but source only data.\n```nginx\n# nginx.conf\n\nserver {\n    ....\n     location /test {\n        elastic_pass http://elastic_upstream;\n        elastic_send POST /testindex/testdoc/_search source;\n        \n        elastic_query '{\"query\":\n           {\n            \"match_all\": {}\n           }\n        }';\n    }\n}\n```\n\n\n### 8. search with dynamic input.\n```nginx\n# nginx.conf\n\nserver {\n    ....\n    location /test {\n        elastic_pass http://elastic_upstream;\n        elastic_send POST /testindex/testdoc/_search;\n        elastic_query $request_body;\n    }\n\n    location /test2 {\n        elastic_pass http://elastic_upstream;\n        elastic_send POST /testindex/testdoc/_search;\n        elastic_query '{\"query\": {\"match\" : {\"$arg_field\" : \"$arg_value\"}}}';\n    }\n}\n```\n\n\n### 9. Delete index.\n```nginx\n# nginx.conf\n\nserver {\n    ....\n    location /test {\n        elastic_pass http://elastic_upstream;\n        elastic_send DELETE /testindex/;\n    }\n}\n```\n\n\n\nInstallation\n============\n\n```bash\nwget 'http://nginx.org/download/nginx-1.13.7.tar.gz'\ntar -xzvf nginx-1.13.7.tar.gz\ncd nginx-1.13.7/\n\n./configure --add-module=/path/to/nginx-elastic-client\n\nmake -j2\nsudo make install\n```\n\n[Back to TOC](#table-of-contents)\n\n\nTest\n=====\n\nIt depends on nginx test suite libs, please refer [test-nginx](https://github.com/openresty/test-nginx) for installation.\n\n\n```bash\ncd /path/to/nginx-elastic-client\nexport PATH=/path/to/nginx-dirname:$PATH \nsudo TEST_NGINX_SLEEP=0.3 prove t\n```\n\n[Back to TOC](#table-of-contents)\n\n\nWhy need this\n==============\n\nNot everyone knows how to query elasticsearch, some client might prefer pass the argument rather than query themselves.\n\nThe query inside the nginx.conf has version controlled, maintained, tracked and it's transparent to every of your team member. Central based and pass to multiple elastic server.\n\nKnown issue faster, make change 1 to every client, if many client has their on client query logic, the issue will be hard to maintained.\n\nClient can be Zero Down time! nginx -s reload make the changed.\n\nNginx is reliable proxy server, the client is auto load-balance upstream to elasticsearch server.\n\n[Back to TOC](#table-of-contents)\n\nSupport\n=======\n\nPlease do not hesitate to contact minikawoon2017@gmail.com for any queries or development improvement.\n\n\n[Back to TOC](#table-of-contents)\n\nCopyright \u0026 License\n===================\n\nCopyright (c) 2018, Taymindis \u003ccloudleware2015@gmail.com\u003e\n\nThis module is licensed under the terms of the BSD license.\n\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n\n1. Redistributions of source code must retain the above copyright notice, this\n   list of conditions and the following disclaimer.\n2. Redistributions in binary form must reproduce the above copyright notice,\n   this list of conditions and the following disclaimer in the documentation\n   and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\nON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n[Back to TOC](#table-of-contents)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTaymindis%2Fnginx-elastic-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FTaymindis%2Fnginx-elastic-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTaymindis%2Fnginx-elastic-client/lists"}