-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
163 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# Velocity for Elasticsearch | ||
|
||
## 安装 | ||
|
||
> 方式 1 - 使用 `elasticsearch-plugin `安装 | ||
```shell script | ||
./bin/elasticsearch-plugin install https://github.com/Ahoo-Wang/elasticsearch-script-velocity/releases/download/v8.11.0/elasticsearch-script-velocity-8.11.0.zip | ||
``` | ||
|
||
> 方式 2 - 从 [Releases](https://github.com/Ahoo-Wang/elasticsearch-script-velocity/releases) 下载构建包 | ||
1. 创建插件目录 `cd your-es-root/plugins/ && mkdir elasticsearch-script-velocity` | ||
2. 解压到该目录 `your-es-root/plugins/elasticsearch-script-velocity` | ||
|
||
## 使用 | ||
|
||
### 存储脚本 | ||
|
||
[create-stored-script-api](https://www.elastic.co/guide/en/elasticsearch/reference/current/create-stored-script-api.html) | ||
|
||
```http request | ||
```http request | ||
POST _scripts/templateid | ||
{ | ||
"script": { | ||
"lang": "velocity", | ||
"source": { | ||
"query": { | ||
"match": { | ||
"title": "$query_string" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### 获取已存储的脚本 | ||
|
||
[get-stored-script-api](https://www.elastic.co/guide/en/elasticsearch/reference/current/get-stored-script-api.html) | ||
|
||
```http request | ||
GET _scripts/templateid | ||
``` | ||
|
||
> 请求响应结果: | ||
```json | ||
{ | ||
"_id": "templateid", | ||
"found": true, | ||
"script": { | ||
"lang": "velocity", | ||
"source": """{"query":{"match":{"title":"$query_string"}}}""", | ||
"options": { | ||
"content_type": "application/json;charset=utf-8" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### 删除已存储的脚本 | ||
|
||
[delete-stored-script-api](https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-stored-script-api.html) | ||
|
||
```http request | ||
DELETE _scripts/templateid | ||
``` | ||
|
||
### 模板搜索 | ||
|
||
[search-template](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html) | ||
|
||
```http request | ||
GET _search/template | ||
{ | ||
"id": "templateid", | ||
"params": { | ||
"query_string": "search for these words" | ||
} | ||
} | ||
``` | ||
|
||
### 验证搜索模板 | ||
|
||
```http request | ||
GET _render/template/templateid | ||
{ | ||
"params": { | ||
"query_string": "search for these words" | ||
} | ||
} | ||
``` | ||
|
||
> 请求响应结果: | ||
```json | ||
{ | ||
"template_output": { | ||
"query": { | ||
"match": { | ||
"title": "search for these words" | ||
} | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[versions] | ||
# libraries | ||
elasticsearch = "8.11.0" | ||
velocity = "2.3" | ||
junit = "4.13.2" | ||
hamcrest = "2.2" | ||
log4j = "2.21.1" | ||
|
||
# plugins | ||
|
||
|
||
[libraries] | ||
elasticsearch = { module = "org.elasticsearch:elasticsearch", version.ref = "elasticsearch" } | ||
velocity = { module = "org.apache.velocity:velocity-engine-core", version.ref = "velocity" } | ||
junit = { module = "junit:junit", version.ref = "junit" } | ||
hamcrest = { module = "org.hamcrest:hamcrest", version.ref = "hamcrest" } | ||
log4j = { module = "org.apache.logging.log4j:log4j-core", version.ref = "log4j" } | ||
|
||
[plugins] | ||
|
||
|
||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip | ||
networkTimeout=10000 | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |