{"id":15985706,"url":"https://github.com/ahoo-wang/elasticsearch-script-velocity","last_synced_at":"2025-03-17T19:31:26.985Z","repository":{"id":41982858,"uuid":"263639865","full_name":"Ahoo-Wang/elasticsearch-script-velocity","owner":"Ahoo-Wang","description":"Bring Velocity to EalsticSearch","archived":false,"fork":false,"pushed_at":"2025-03-14T15:45:47.000Z","size":318,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-14T16:37:10.500Z","etag":null,"topics":["elasticsearch","script","search-template","velocity"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ahoo-Wang.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-13T13:36:03.000Z","updated_at":"2025-02-26T02:26:56.000Z","dependencies_parsed_at":"2023-10-01T19:43:52.982Z","dependency_job_id":"87d2dabb-9191-49f4-a54c-e24f63bcdd25","html_url":"https://github.com/Ahoo-Wang/elasticsearch-script-velocity","commit_stats":{"total_commits":69,"total_committers":4,"mean_commits":17.25,"dds":0.536231884057971,"last_synced_commit":"f178a34b1ca5571bcdd9d5fc4b1b1b997897a069"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ahoo-Wang%2Felasticsearch-script-velocity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ahoo-Wang%2Felasticsearch-script-velocity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ahoo-Wang%2Felasticsearch-script-velocity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ahoo-Wang%2Felasticsearch-script-velocity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ahoo-Wang","download_url":"https://codeload.github.com/Ahoo-Wang/elasticsearch-script-velocity/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243878439,"owners_count":20362432,"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":["elasticsearch","script","search-template","velocity"],"created_at":"2024-10-08T02:24:03.878Z","updated_at":"2025-03-17T19:31:26.486Z","avatar_url":"https://github.com/Ahoo-Wang.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Velocity for Elasticsearch\n\n[![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)\n[![GitHub release](https://img.shields.io/github/release/Ahoo-Wang/elasticsearch-script-velocity.svg)](https://github.com/Ahoo-Wang/elasticsearch-script-velocity/releases)\n[![codecov](https://codecov.io/gh/Ahoo-Wang/elasticsearch-script-velocity/graph/badge.svg?token=QK8XZXHBZN)](https://codecov.io/gh/Ahoo-Wang/elasticsearch-script-velocity)\n![Integration Test Status](https://github.com/Ahoo-Wang/elasticsearch-script-velocity/actions/workflows/integration-test.yml/badge.svg)\n\n*Search Template* is a highly valuable feature in Elasticsearch. It allows the pre-definition of the query structure for search requests, with the ability to pass search parameters during the actual request. This not only makes the request body more concise but also helps avoid errors that may occur when concatenating query structures on the client side.\n\nWhen search optimization is necessary, modifications to search scripts can be made directly on the Elasticsearch server without the need to redeploy the client. This significantly enhances the efficiency of search optimization.\n\nHowever, the [default scripting languages](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html#scripting-available-languages) (`mustache`/`painless`/`expression`) supported by *Elasticsearch* have relatively limited syntax logic, lacking support for any conditional statements. This imposes significant constraints on the use of *Search Template*.\n\nBy introducing *Velocity* into *Elasticsearch*, support for any conditional statements is enabled, making the usage of *Search Template* more flexible. This provides users with greater customization capabilities for powerful and flexible searches.\n\n## Version Convention\n\n\u003e version = `elasticsearchVersion`-`pluginVersion`\n\n## Install\n\n\u003e optional 1 - use elasticsearch-plugin to install\n\u003e \n\u003e Tip: Replace [version] in the link with your Elasticsearch version\n\n```shell script\n./bin/elasticsearch-plugin install https://github.com/Ahoo-Wang/elasticsearch-script-velocity/releases/download/v[version]/elasticsearch-script-velocity-[version].zip\n```\n\u003e optional 2 - download pre-build package from here: [Releases](https://github.com/Ahoo-Wang/elasticsearch-script-velocity/releases)\n\n1. create plugin folder `cd your-es-root/plugins/ \u0026\u0026 mkdir elasticsearch-script-velocity`\n2. unzip plugin to folder `your-es-root/plugins/elasticsearch-script-velocity`\n\n## Use\n\n### Store script\n\n[create-stored-script-api](https://www.elastic.co/guide/en/elasticsearch/reference/current/create-stored-script-api.html)\n\n```http request\nPOST _scripts/templateid\n{\n    \"script\": {\n        \"lang\": \"velocity\",\n        \"source\": {\n            \"query\": {\n                \"match\": {\n                    \"title\": \"$query_string\"\n                }\n            }\n        }\n    }\n}\n```\n### Get Stored Script\n\n[get-stored-script-api](https://www.elastic.co/guide/en/elasticsearch/reference/current/get-stored-script-api.html)\n\n```http request\nGET _scripts/templateid\n```\n\n\u003e Response:\n\n```json\n{\n  \"_id\" : \"templateid\",\n  \"found\" : true,\n  \"script\" : {\n    \"lang\" : \"velocity\",\n    \"source\" : \"\"\"{\"query\":{\"match\":{\"title\":\"$query_string\"}}}\"\"\",\n    \"options\" : {\n      \"content_type\" : \"application/json; charset=UTF-8\"\n    }\n  }\n}\n```\n\n### Delete a stored script\n\n[delete-stored-script-api](https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-stored-script-api.html)\n\n```http request\nDELETE _scripts/templateid\n```\n\n### Search template\n\n[search-template](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html)\n\n```http request\nGET _search/template\n{\n    \"id\": \"templateid\", \n    \"params\": {\n        \"query_string\": \"search for these words\"\n    }\n}\n```\n\n### Validating a search template\n\n```http request\nGET _render/template/templateid\n{\n  \"params\": {\n    \"query_string\": \"search for these words\"\n  }\n}\n```\n\n\u003e Response:\n\n```json\n{\n  \"template_output\" : {\n    \"query\" : {\n      \"match\" : {\n        \"title\" : \"search for these words\"\n      }\n    }\n  }\n}\n```\n\n## Benchmark\n\n```\nBenchmark                                             Mode  Cnt        Score   Error  Units\nVelocityScriptEngineBenchmark.executeSearchTemplate  thrpt       1020003.447          ops/s\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahoo-wang%2Felasticsearch-script-velocity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahoo-wang%2Felasticsearch-script-velocity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahoo-wang%2Felasticsearch-script-velocity/lists"}