Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Query at the Elasticsearch scaler #1480

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 78 additions & 5 deletions content/docs/2.16/scalers/elasticsearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ title = "Elasticsearch"
availability = "v2.5+"
maintainer = "Community"
category = "Data & Storage"
description = "Scale applications based on elasticsearch search template query result."
description = "Scale applications based on 'elasticsearch search template query' or 'elasticsearch query' result."
go_file = "elasticsearch_scaler"
+++

### Trigger Specification

This specification describes the `elasticsearch` trigger that scales based on result of an [elasticsearch search template](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html) query.
This specification describes the `elasticsearch` trigger that scales based on result of an [elasticsearch search template](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html) query or [elasticsearch query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html).

The trigger always requires the following information:
The trigger always requires the following information, but requires either only searchTemplateName **or** only query:

```yaml
triggers:
Expand All @@ -22,6 +22,7 @@ triggers:
passwordFromEnv: "ELASTIC_PASSWORD"
index: "my-index"
searchTemplateName: "my-search-template-name"
query: "my-query"
parameters: "param1:value1;param2:value2"
valueLocation: "hits.total.value"
targetValue: "1.1"
Expand All @@ -35,6 +36,7 @@ triggers:
- `passwordFromEnv` - Environment variable to read the authentication password from to authenticate with the Elasticsearch cluster.
- `index` - Comma separated list of indexes to run the search template query on.
- `searchTemplateName` - The search template name to run.
- `query` - The query to run.
- `targetValue` - Target value to scale on. When the metric provided by the API is equal or higher to this value, KEDA will start scaling out. When the metric is 0 or less, KEDA will scale down to 0. (This value can be a float)
- `activationTargetValue` - Target value for activating the scaler. Learn more about activation [here](./../concepts/scaling-deployments.md#activating-and-scaling-thresholds).(Default: `0`, Optional, This value can be a float)
- `parameters` - Parameters that will be used by the search template. It supports multiples params separated by a semicolon character ( `;` ).
Expand All @@ -57,9 +59,9 @@ You can authenticate by using a username/password or apiKey/cloudID if you're us
- `cloudID` - CloudID to connect with ElasticSearch on Elastic Cloud.
- `apiKey` - API key to authenticate with ElasticSearch on Elastic Cloud.

### Example
### Examples

Here is an example of how to deploy a scaled object with the `elasticsearch` scale trigger which uses `TriggerAuthentication`.
Here is an example of how to deploy a scaled object with the `elasticsearch` scale trigger which uses the search template and `TriggerAuthentication`.

```yaml
apiVersion: v1
Expand Down Expand Up @@ -100,3 +102,74 @@ spec:
authenticationRef:
name: keda-trigger-auth-elasticsearch-secret
```
Here is an example of how to deploy a scaled object with the `elasticsearch` scale trigger which uses `query`. In this example the transactions will be count that the application has to process based on APM.

```yaml
apiVersion: v1
kind: Secret
metadata:
name: elasticsearch-secrets
type: Opaque
data:
password: cGFzc3cwcmQh
---
apiVersion: keda.sh/v1alpha1
kind: TriggerAuthentication
metadata:
name: keda-trigger-auth-elasticsearch-secret
spec:
secretTargetRef:
- parameter: password
name: elasticsearch-secrets
key: password
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: elasticsearch-scaledobject
spec:
scaleTargetRef:
name: "deployment-name"
triggers:
- type: elasticsearch
metadata:
addresses: "http://localhost:9200"
username: "elastic"
index: "my-index"
query: |
{
"size": 0,
"query": {
"bool": {
"must": [
{
"term": {
"service.name": "my-application" }
},
{
"term": {
"service.environment": "production" }
},
{
"range": {
"@timestamp": {
"gte": "now-2m",
"lte": "now-1m"
}
}
}
]
}
},
"aggs": {
"transaction_count": {
"cardinality": {
"field": "transaction.id" }
}
}
}
valueLocation: "aggregations.transaction_count.value"
targetValue: "1000"
authenticationRef:
name: keda-trigger-auth-elasticsearch-secret
```