Skip to content

Commit

Permalink
update elasticsearch to v8.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahoo-Wang committed Nov 10, 2023
1 parent e93a84b commit 463c19a
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 30 deletions.
36 changes: 19 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

## Install

### Download

#### optional 1 - use elasticsearch-plugin to install
> optional 1 - use elasticsearch-plugin to install
```shell script
./bin/elasticsearch-plugin install https://github.com/Ahoo-Wang/elasticsearch-script-velocity/releases/download/v7.10.2/elasticsearch-script-velocity-7.10.2.zip
```
#### optional 2 - download pre-build package from here: https://github.com/Ahoo-Wang/elasticsearch-script-velocity/releases
> optional 2 - download pre-build package from here: [Releases](https://github.com/Ahoo-Wang/elasticsearch-script-velocity/releases)
1. create plugin folder `cd your-es-root/plugins/ && mkdir elasticsearch-script-velocity`
2. unzip plugin to folder `your-es-root/plugins/elasticsearch-script-velocity`

## Demo
## Use

### Store a search template
You can store a search template using the stored scripts API.
### Store script

[create-stored-script-api](https://www.elastic.co/guide/en/elasticsearch/reference/current/create-stored-script-api.html)

```http request
POST _scripts/templateid
Expand All @@ -34,13 +33,15 @@ POST _scripts/templateid
}
}
```
The template can be retrieved by calling
### Get Stored Script

[get-stored-script-api](https://www.elastic.co/guide/en/elasticsearch/reference/current/get-stored-script-api.html)

```http request
GET _scripts/templateid
```
The API returns the following result:

> Response:
```json
{
Expand All @@ -55,16 +56,18 @@ The API returns the following result:
}
}
```
This template can be deleted by calling

### Delete a stored script

[delete-stored-script-api](https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-stored-script-api.html)

```http request
DELETE _scripts/templateid
```

### Using a stored search template
### Search template

To use a stored template at search time send the following request:
[search-template](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html)

```http request
GET _search/template
Expand All @@ -78,8 +81,6 @@ GET _search/template

### Validating a search template

A template can be rendered in a response with given parameters by using the following request:

```http request
GET _render/template/templateid
{
Expand All @@ -88,7 +89,8 @@ GET _render/template/templateid
}
}
```
The API returns the rendered template:

> Response:
```json
{
Expand Down
109 changes: 109 additions & 0 deletions README.zh-CN.md
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"
}
}
}
}
```
15 changes: 5 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This project uses @Incubating APIs which are subject to change.
*/
plugins {
id("elasticsearch.esplugin")
id("elasticsearch.yaml-rest-test")
Expand All @@ -28,11 +23,11 @@ java {
}

dependencies {
compileOnly("org.elasticsearch:elasticsearch:${project.properties["elasticsearchVersion"]}")
implementation("org.apache.velocity:velocity-engine-core:2.3")
yamlRestTestRuntimeOnly("junit:junit:4.13.2") {
compileOnly(libs.elasticsearch)
implementation(libs.velocity)
yamlRestTestRuntimeOnly(libs.junit) {
exclude("org.hamcrest")
}
yamlRestTestRuntimeOnly("org.hamcrest:hamcrest:2.2")
yamlRestTestRuntimeOnly("org.apache.logging.log4j:log4j-core:2.19.0")
yamlRestTestRuntimeOnly(libs.hamcrest)
yamlRestTestRuntimeOnly(libs.log4j)
}
5 changes: 2 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
# limitations under the License.
#
group=me.ahoo.elasticsearch
version=8.5.2
description=elasticsearch-script-velocity
elasticsearchVersion=8.5.2
version=8.11.0
description=elasticsearch-script-velocity
22 changes: 22 additions & 0 deletions gradle/libs.versions.toml
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 added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
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

0 comments on commit 463c19a

Please sign in to comment.